7

What flags for either gcc or clang will improve compile times? I require debugging to be enabled but any other features are free to be disabled if they will result in faster compiles.

I know there are numerous other ways to improve compile times but I am interested soley in this area.

2
  • that's the best you can hope to do as far as speeding up compilation times from twiddling with flags. There are no flags that will just magically make compile times faster. You'll have to look into other ways of improving build times. Commented Jan 5, 2012 at 22:42
  • 1
    Waving white flags might help. Also, -c or -E are definitely known to improve compile times. In all cases: show us some code and we can begin to hint on ways to improve build times. Commented Jun 15, 2012 at 12:55

5 Answers 5

7

The largest gain in compile time is found by eliminating the most work done by the compiler - usually optimisation. So, don't enable optimisation (-O) flags.

Sign up to request clarification or add additional context in comments.

6 Comments

Adding -O0 did not help. Right now I use these flags: -g3 -O0 -Wfatal-errors -Wall -Wno-unused-variable -Wno-unused-function -Wall -W -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations -ffast-math -Wno-missing-declarations
Adding -O0 is doing exactly what Greg said to do. It is disabling optimization.
Adding -O0 when I did not have any -O flags to begin with did not seem to have any effect. I see I made a mistake above, 'right now' should not have included -O0.
Yes, the default (at least for gcc) is the lack of a -O flag means no optimisations are enabled. Note that if you wanted us to provide specific recommendations to change your compiler command line, you probably should have provided your compiler command line in the question.
I would humbly suggest that using no flags at all will likely result in the fastest compile times. I don't know of any magic --fast-compile switch that will make the compiler take less time.
|
3

Try -O1, despite it being counter intuitive afaik it can speed up compilation compared to -O0. Also check out ccache

1 Comment

ccache does nothing to decrease compile time. It may decrease build time, by preventing compilation
3

You can also try using precompiled headers.

Comments

2

As for GCC, you can try multithreaded compilation (-jX flag, where X is a number of cores you have +1, according to Reducing compile times article in the Qt Centre).

UPDATE: It seems that I made a mistake: -jX is a 'make' flag, not GCC. So it will improve linking times if you use make-based build system.

Comments

-4

If we start with our base line as 'compiling with no flags' there are no flags you can set that will increase the compilation time.

1 Comment

huh. did you accidentally invert a word?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.