53

The project that I am trying to build has default flags

CFLAGS = -Wall -g -O2 CXXFLAGS = -g -O2 

I need to append a flag -w to both these variables (to remove: 'consider all warnings as errors')

I have a method to work it out, give

make 'CFLAGS=-Wall -g -O2 -w'; 'CXXFLAGS=-g -O2 -w' 

OR

Run ./configure and statically modify Makefile

But I want to append my options with the existing options while running configure or make

The post Where to add a CFLAG, such as -std=gnu99, into an autotools project conveniently uses a macro to achieve this.

2 Answers 2

81

You almost have it right; why did you add the semicolon?

To do it on the configure line:

 ./configure CFLAGS='-g -O2 -w' CXXFLAGS='-g -O2 -w' 

To do it on the make line:

 make CFLAGS='-g -O2 -w' CXXFLAGS='-g -O2 -w' 

However, that doesn't really remove consider all warnings as errors; that removes all warnings. So specifying both -Wall and -w doesn't make sense. If you want to keep the warnings but not have them considered errors, use the -Wall -Wno-error flags.

Alternatively, most configure scripts which enable -Werror by default also have a flag such as --disable-werror or similar. Run ./configure --help and see if there's something like that.

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

5 Comments

Is there a way for me to NOT specify this statitcally evertime, like, CFLAGS=' $CFLAGS <my-options>', to retain whatever is already configured and without knowing it as well.
No, that's not possible (at least not without modifying the makefile). According to the autoconf coding standards the default value of CFLAGS is always only enabling debugging/optimization, so it should normally always be -g -O2 for most systems. It's not correct (according to the coding standards) to add other important flags such as -I, -D, etc. into CFLAGS. So it should be safe to always just override it.
If you cannot assign CFLAGS without retaining the package defaults, then the software packaging contains a bug which should be reported to the package maintainer.
This does not answer the question. The question was how to append options to existing default options without explicit writing all of them.
No it wasn't. There's nothing in the original question that says "without writing all of them". It just asks how to append options with existing options.
2

I ran into the same issue and could not find an easy solution either. What I did was modify the Makefile template (Makefile.config.in). For example, the template had a line

CFLAGS = @CFLAGS@ @DEFS@ $(C_COMPILE_FLAGS) 

which I changed to

CFLAGS = @CFLAGS@ @DEFS@ $(C_COMPILE_FLAGS) $(CFLAGS_USER) 

Afterwards, I could use this like:

./configure [options] make CFLAGS_USER="-fPIC" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.