问题描述
我尝试构建的项目具有默认标志
The project that I am trying to build has default flags
CFLAGS = -Wall -g -O2
CXXFLAGS = -g -O2
我需要为这两个变量附加一个标志 -w
(删除:'将所有警告视为错误')
I need to append a flag -w
to both these variables (to remove: 'consider all warnings as errors')
我有办法解决,给
make 'CFLAGS=-Wall -g -O2 -w'; 'CXXFLAGS=-g -O2 -w'
或
运行./configure
并静态修改Makefile
但我想在运行 configure
或 make
帖子在哪里添加 CFLAG,比如-std=gnu99,进入一个autotools项目方便地使用宏来实现这一点.
The postWhere to add a CFLAG, such as -std=gnu99, into an autotools projectconveniently uses a macro to achieve this.
推荐答案
你几乎说对了;为什么要加分号?
You almost have it right; why did you add the semicolon?
在 configure
行上做:
./configure CFLAGS='-g -O2 -w' CXXFLAGS='-g -O2 -w'
在 make
行上做:
make CFLAGS='-g -O2 -w' CXXFLAGS='-g -O2 -w'
然而,这并不能真正消除将所有警告视为错误;删除所有警告.所以同时指定 -Wall
和 -w
是没有意义的.如果您想保留警告但不将它们视为错误,请使用 -Wall -Wno-error
标志.
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.
或者,大多数默认启用 -Werror
的 configure
脚本也有一个标志,例如 --disable-werror
或类似的.运行 ./configure --help
看看是否有类似的东西.
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.
这篇关于在配置/制作时将编译标志附加到 CFLAGS 和 CXXFLAGS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!