使用多个内核通过g ++进行编译 [英] Compiling with g++ using multiple cores

查看:164
本文介绍了使用多个内核通过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).

例如,如果你想要4个并行作业:

For example if you want 4 parallel jobs from make:

make -j 4

在管道中运行gcc

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天全站免登陆