2

I have a makefile that compiles C++ files with a rule rather like this:

$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(FILE) $(DEFINE) $(INCLUDE) $(USER_CXXFLAGS)" 

For a particular configuration of the build system, $(CXXFLAGS) includes the value -O2. But, I can add my own flags to $(USER_CXXFLAGS), and for easier debugging want to add -O0. The end result of this is that when compilation is done, the compiler command line will include multiple conflicting instructions about how to optimize.

Which one does it use? I suspect it's reasonable to assume that the last specified option takes precedence, but given that position matters for some G++ options I don't want to make that assumption. Is this behavior documented somewhere? I read the man pages but was unable to find any specification about repeated options in general.

8
  • same? Commented Apr 15, 2015 at 23:05
  • AFAICR, the de facto mode of operation is the 'last takes precedence' when you work with things like -std=c99 vs -std=gnu11, so I would expect the same to apply to other options such as -O. Commented Apr 15, 2015 at 23:06
  • As far as I can tell, the -O0 option has taken effect over the previous -O2 but I'll still welcome anyone who quotes whatever deeply buried documentation states that this is true in all cases. Commented Apr 15, 2015 at 23:06
  • @DrewDormann i would say this is actually a duplicate of that question. Commented Apr 15, 2015 at 23:07
  • @Ben You're not alone. :) Commented Apr 15, 2015 at 23:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.