Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

makefile - Append compile flags to CFLAGS and CXXFLAGS while configuration/make

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...