GCC/Make Build Time Optimizations

前端 未结 10 670
鱼传尺愫
鱼传尺愫 2021-02-02 01:22

We have project which uses gcc and make files. Project also contains of one big subproject (SDK) and a lot of relatively small subprojects which use that SDK and some shared fra

10条回答
  •  一个人的身影
    2021-02-02 02:19

    The best I can think of with make is the -j option. This tells make to run as many jobs as possible in parallel:

    make -j

    If you want to limit the number of concurrent jobs to n you can use:

    make -j n


    Make sure the dependencies are correct so make doesn't run jobs it doesn't have to.


    Another thing to take into account is optimizations that gcc does with the -O switch. You can specify various levels of optimization. The higher the optimization, the longer the compile and link times. A project I work with runs takes 2 minutes to link with -O3, and half a minute with -O1. You should make sure you're not optimizing more than you need to. You could build without optimization for development builds and with optimization for deployment builds.


    Compiling with debug info (gcc -g) will probably increase the size of your executable and may impact your build time. If you don't need it, try removing it to see if it affects you.


    The type of linking (static vs. dynamic) should make a difference. As far as I understand static linking takes longer (though I may be wrong here). You should see if this affects your build.

提交回复
热议问题