Compiling with g++ using multiple cores

后端 未结 8 2376
猫巷女王i
猫巷女王i 2020-11-29 15:47

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

8条回答
  •  悲&欢浪女
    2020-11-29 16:11

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

    For example if you want 4 parallel jobs from make:

    make -j 4
    

    You can also run gcc in a pipe with

    gcc -pipe
    

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

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

提交回复
热议问题