What flags will improve gcc / clang compilation time?

What flags for gcc or clang will improve compilation time? I need debugging turned on, but any other functions can be turned off if they lead to faster compilations.

I know that there are many other ways to improve compilation time, but I'm interested in this area.

+4
source share
6 answers

The greatest gain during compilation was found, eliminating most of the work performed by the compiler - usually optimization. Therefore, do not enable the optimization flags ( -O ).

+6
source

As for GCC, you can try multi-threaded compilation (the -jX flag, where X is the number of cores that have +1, according to Reducing compilation time in the Qt Center).

UPDATE: It seems I made a mistake: -jX is the make flag, not GCC. Thus, this will improve the binding time if you use a make-based build system.

+3
source

You can also try using precompiled headers.

+3
source

Try -O1, although it is an intuitive afaik counter, it can speed up compilation compared to -O0. Also check ccache

+1
source

If we start with our base line as “compilation without flags”, the flags you can set do not increase compilation time.

0
source

If you have access to more processors on the network, you can use distcc

0
source

Source: https://habr.com/ru/post/1389553/


All Articles