简体   繁体   English

使SCons在一条gcc行中编译所有内容?

[英]make SCons compile everything in one gcc line?

I have a rather complex SCons script that compiles a big C++ project. 我有一个相当复杂的SCons脚本,可以编译一个大型C ++项目。
This gcc manual page says: 这个gcc手册页说:

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. 一次将多个文件编译为一个输出文件模式,使编译器可以在编译每个文件时使用从所有文件获得的信息。

So it's better to give all my files to a single g++ invocation and let it drive the compilation however it pleases. 因此,最好将我的所有文件都交给一个g++调用,然后让它随心所欲地驱动编译。
But SCons does not do this. 但是SCons不会这样做。 it calls g++ separately for every single C++ file in the project and then links them using ld 它分别为项目中的每个C ++文件调用g++ ,然后使用ld链接它们

Is there a way to make SCons do this? 有没有办法让SCons做到这一点?

The main reason to have a build system with the ability to express dependencies is to support some kind of conditional/incremental build. 拥有能够表达依赖性的构建系统的主要原因是支持某种条件/增量构建。 Otherwise you might as well just use a script with the one command you need. 否则,您可能只需将脚本与所需的一个命令一起使用。

That being said, the result of having gcc/g++ optimize as the manual describe is substantial. 话虽如此,如手册所述,使gcc / g ++优化的结果是可观的。 In particular if you have C++ templates you use often. 特别是如果您有C ++模板,则经常使用。 Good for run-time performance, bad for recompile performance. 有利于运行时性能,不利于重新编译性能。

I suggest you try and make your own builder doing what you need. 我建议您尝试使自己的构建器做您需要的事情。 Here is another question with an inspirational answer: SCons custom builder - build with multiple files and output one file 这是一个鼓舞人心的答案的另一个问题: SCons定制构建器-使用多个文件构建并输出一个文件

Currently the answer is no. 目前答案是否定的。

Logic similar to this was developed for MSVC only. 与此类似的逻辑仅适用于MSVC。 You can see this in the man page ( http://scons.org/doc/production/HTML/scons-man.html ) as follows: 您可以在手册页( http://scons.org/doc/production/HTML/scons-man.html )中看到以下内容:

MSVC_BATCH When set to any true value, specifies that SCons should batch compilation of object files when calling the Microsoft Visual C/C++ compiler. MSVC_BATCH设置为任何true值时,指定SCons在调用Microsoft Visual C / C ++编译器时应批量编译目标文件。 All compilations of source files from the same source directory that generate target files in a same output directory and were configured in SCons using the same construction environment will be built in a single call to the compiler. 来自同一源目录的源文件的所有编译,都会在同一输出目录中生成目标文件,并且使用相同的构造环境在SCons中进行配置,这些编译将通过一次对编译器的调用来构建。 Only source files that have changed since their object files were built will be passed to each compiler invocation (via the $CHANGED_SOURCES construction variable). 仅将自生成目标文件以来已更改的源文件传递给每个编译器调用(通过$ CHANGED_SOURCES构造变量)。 Any compilations where the object (target) file base name (minus the .obj) does not match the source file base name will be compiled separately. 对象(目标)文件基本名称(减去.obj)与源文件基本名称不匹配的所有编译都将单独编译。

As always patches are welcome to add this in a more general fashion. 与往常一样,欢迎以更一般的方式添加补丁。

In general this should be left up to the program developer. 通常,这应该留给程序开发人员。 Trying to compile all together in an amalgamation may introduce unintended behaviour to the program if it even compiles in the first place. 尝试将所有内容合并在一起进行编译可能会给程序带来意想不到的行为,即使该程序最初是编译的。 Your best bet if you want this kind of optimisation without editing the source yourself is to use a compiler with inter-process optimisation like icc -ipo . 如果您想要这种优化而不自己编辑源代码,那么最好的选择是使用具有进程间优化的编译器,例如icc -ipo

Example where an amalgamation of two .c files would not compile is for example if they use two identical static symbols with different functionality. 例如,如果两个.c文件的合并使用两个具有不同功能的相同static符号,则它们将无法编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM