Compiling with g++ using multiple cores(使用多核使用 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.
这篇关于使用多核使用 g++ 编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用多核使用 g++ 编译


基础教程推荐
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01