Append compile flags to CFLAGS and CXXFLAGS while configuration/make

风格不统一 提交于 2019-11-27 00:53:06

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23407635/append-compile-flags-to-cflags-and-cxxflags-while-configuration-make

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!