C编译器能够跨目标文件进行优化吗? [英] Is C compiler able to optimize across object file?

查看:116
本文介绍了C编译器能够跨目标文件进行优化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑仅标头与标头与源代码设计之间的关系.我不确定header& source是否允许编译器跨目标文件和跨链接进行优化?如内联优化?

I'm considering between header-only vs. header&source design. I'm not sure if the header&source allows compiler to optimize across object files and across linkage ? such as inlining optimization ?

推荐答案

头文件和源文件通常编译为单个翻译单元(因为头文件包含在源文件中).因此,这将不是问题(除非您有一个特殊的环境, 标头是单独编译的.

Header files and source files typically compiled as a single translation unit (since headers are included in the source files). So, that won't be an issue (unless you have a peculiar environment where headers are compiled separately).

GCC确实支持跨不同翻译部门的优化.请参见链接时间优化.

GCC does support optimizations across different translation units. See Link Time Optimization.

有关详细信息,请参见 -flto 选项的文档:

See the -flto option's documentation for details:

-flto [= n]

-flto[=n]

此选项运行标准链接时间优化器.当与 源代码,它会生成GIMPLE(GCC内部 表示形式)并将其写入对象中的特殊ELF部分 文件.将目标文件链接在一起时,所有功能 从这些ELF部分读取正文并将其实例化,就像它们 曾经是同一个翻译部门的成员.使用链接时间 优化器,-flto和优化选项应在以下位置指定 编译时间和最终链接期间.建议你 用相同的编译所有参与相同链接的文件 选项,并在链接时指定这些选项.

This option runs the standard link-time optimizer. When invoked with source code, it generates GIMPLE (one of GCC's internal representations) and writes it to special ELF sections in the object file. When the object files are linked together, all the function bodies are read from these ELF sections and instantiated as if they had been part of the same translation unit. To use the link-time optimizer, -flto and optimization options should be specified at compile time and during the final link. It is recommended that you compile all the files participating in the same link with the same options and also specify those options at link time.

这篇关于C编译器能够跨目标文件进行优化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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