我有一个相当复杂的 SCons 脚本,用于编译一个大型 C++ 项目。
This gcc manual页面说:
The compiler performs optimization based on the knowledge it has of the program. Compiling multiple files at once to a single output file mode allows the compiler to use information gained from all of the files when compiling each of them.
因此,最好将我的所有文件交给一个 g++
调用,并让它随心所欲地驱动编译。
但 SCons 不这样做。它为项目中的每个 C++ 文件单独调用 g++
,然后使用 ld
链接它们
有没有办法让 SCons 做到这一点?
最佳答案
拥有能够表达依赖关系的构建系统的主要原因是支持某种条件/增量构建。否则,您不妨只使用带有您需要的一个命令的脚本。
话虽如此,按照手册描述进行 gcc/g++ 优化的结果是显着的。特别是如果您有经常使用的 C++ 模板。有利于运行时性能,但有利于重新编译性能。
我建议你尝试让你自己的构建器做你需要的事情。这是另一个具有鼓舞人心答案的问题:SCons custom builder - build with multiple files and output one file
关于c++ - 让 SCons 在一行 gcc 中编译所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24248140/