g ++编译器标志 - 用于创建静态库的优化和标志 - C ++ [英] g++ compiler flags - Optimization and flags for making a static library - C++

查看:91
本文介绍了g ++编译器标志 - 用于创建静态库的优化和标志 - C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从linux上的g ++编译器开始,并得到了关于编译器标志的一些问题。这是他们



优化



我阅读了关于优化标志-O1, O2和-O3在g ++手册页。我不明白什么时候使用这些标志。通常什么优化级别你使用? g ++手册说明了-O2的以下内容。


进一步优化。 GCC执行几乎所有支持的优化,不涉及空间速度权衡。当指定-O2时,编译器不执行循环展开或函数内联。与-O相比,此选项增加了编译时间和生成代码的性能。


如果不进行内联和循环展开,如何实现所述性能提升,是否推荐使用此选项?

静态库



如何使用g ++创建静态库?在Visual Studio中,我可以选择一个类库项目,它将被编译成lib文件。

解决方案

在g ++中等效的是什么?



<

经验法则:



当需要调试时,使用-O0(和-g来生成调试符号。)



当您准备发货时,请使用-O2。



当您使用gentoo时,请使用-O3 ...!

当您需要将其放在嵌入式系统上时,请使用-Os(对大小进行优化,而不是为了提高效率。)


I am just starting with g++ compiler on LINUX and got some questions on the compiler flags. Here are they

Optimizations

I read about optimization flags -O1,-O2 and -O3 in the g++ manual page. I didn't understood when to use these flags. Usually what optimization level do you use? g++ manual says the following for -O2.

Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.

If it is not doing inlining and loop unrolling, how the said performance befits are achieved and is this option recommended?

Static Library

How do I create a static library using g++? In Visual Studio, I can choose a class library project and it will be compiled into "lib" file. What is the equivalent in g++?

Any help would be great.

解决方案

The rule of thumb:

When you need to debug, use -O0 (and -g to generate debugging symbols.)

When you are preparing to ship it, use -O2.

When you use gentoo, use -O3...!

When you need to put it on an embedded system, use -Os (optimize for size, not for efficiency.)

这篇关于g ++编译器标志 - 用于创建静态库的优化和标志 - C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆