Quick way to override -Werror flag?
Asked Answered
M

2

14

If cc configuration is set to use -Werror is there a way to override -Werror flag from the terminal when using make?

Meuse answered 1/8, 2012 at 0:33 Comment(3)
Pass -Wno-error afterward to the compiler, probably putting in CFLAGS in the makefile will do.Nationwide
See Make: Override a flag to do this in a Makefile instead of from the terminal. There’s a better answer in that case.Lyford
Finally I resolved this issue by modifying source files to remove -Werror, using this command find . -name Makefile -or -name '*m4' -exec sed -i s/-Werror//g {} \; Be sure to make a backup before using as it may break things. You may have to adjust find to find files that contains make definitions.Intercut
W
19

You can set flags when invoking make:

CFLAGS=-Wno-error make
Whew answered 1/8, 2012 at 0:41 Comment(2)
This probably won't work. Most makefiles have a default setting of CFLAGS, something like CFLAGS = -O2 -g or something. In order to override that you have to pass the assignment on the command line not in the environment: run make CFLAGS=-Wno-error instead.Fusible
@Fusible Good point, but if you pass the CFLAGS assignment as an argument to make it'll clobber whatever would've been set and potentially break the build entirely (unless only -Werror was set). If that's the case, then the best way is really via ./configure --extra-cflags if available.Whew
F
0

If you have a specific warning, you can remove only that particular warning to error conversion, so other errors will still trigger. This is useful if you know you'll hit the error in your build but do not wish to disable all warnings-errors in case others may be useful.

For example, if you get this warning (error):

error: format not a string literal, format string not checked [-Werror=format-nonliteral]

then use format-nonliteral in -Wno-error=<err> as follows:

CFLAGS=-Wno-error=format-nonliteral

Also note: It is possible that you'll need to redo ./configure if make doesn't pick up CFLAGS directly:

CFLAGS=-Wno-error=format-nonliteral ./configure <options>
make

For C++ you would use CXXFLAGS instead of (or in addition to) CFLAGS.

Feuchtwanger answered 11/4 at 1:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.