使用g ++制作静态库的优化和标志 [英] Optimization and flags for making a static library with g++

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

问题描述

我刚开始在Linux上使用g ++编译器,并在编译器标志上提出了一些问题。这里是他们



优化



c> -O1 , -O2 -O3 在g ++手册页中。我不明白何时使用这些标志。通常你使用什么优化级别? g ++手册为 -O2

说明以下内容:


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


如果不进行内联和循环展开,上述性能如何实现,并且建议使用此选项?



静态库



如何使用g ++创建静态库?在Visual Studio中,我可以选择一个类库项目,并将其编译为lib文件。根据经验:










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

准备发货时,使用-O2。

p>

使用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? The 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++?

解决方案

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 ++制作静态库的优化和标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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