使用多核使用 g++ 编译 [英] Compiling with g++ using multiple cores

查看:54
本文介绍了使用多核使用 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++ 编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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