使用多核使用 g++ 编译

快速问题:允许 g++ 生成多个自身实例以更快地编译大型项目(例如,对于多核 CPU,一次 4 个源文件)的编译器标志是什么?

Quick question: what is the compiler flag to allow g++ to spawn multiple instances of itself in order to compile large projects quicker (for example 4 source files at a time for a multi-core CPU)?

推荐答案

你可以用 make 做到这一点 - 用 gnu make 它是 -j 标志(这对单处理器机器也有帮助).

You can do this with make - with gnu make it is the -j flag (this will also help on a uniprocessor machine).

例如,如果您想要 make 的 4 个并行作业:

For example if you want 4 parallel jobs from make:

make -j 4

您也可以使用

gcc -pipe

这将流水线化编译阶段,这也将有助于保持内核忙碌.

This will pipeline the compile stages, which will also help keep the cores busy.

如果您还有其他可用的机器,您可以查看 distcc,它将农场编译到那些也是.

If you have additional machines available too, you might check out distcc, which will farm compiles out to those as well.

相关文章