I am running on a CentOS 5.7 system.
I downloaded a source package and a .spec file from someone else. I am trying to build a RPM from the source using a vanilla command like:
% rpmbuild -ba ~/rpmbuild/SPECS/foo.spec
...
Configuration summary:
======================
Host type................: x86_64-redhat-linux-gnu
CC.......................: gcc
CFLAGS...................: -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror
Package..................: sudosh2
Version..................: 1.0.4
Installation prefix......: /usr
Man directory............: /usr/share/man
sysconfdir...............: /etc
recording input..........: no
However, this build is failing. The code is a little sloppy and is generating some warnings. Some part of this toolchain is enabling -Werror flag, which makes “all warnings into errors.” Thus, the build fails with an error:
gcc -DHAVE_CONFIG_H -I. -I.. -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror -MT parse.o -MD -MP -MF .deps/parse.Tpo -c -o parse.o parse.c
cc1: warnings being treated as errors
sudosh.c: In function 'main':
sudosh.c:486: warning: unused variable 'written'
sudosh.c:112: warning: unused variable 'found'
cc1: warnings being treated as errors
parse.c: In function 'parse':
parse.c:20: warning: unused variable 'y'
parse.c:14: warning: unused variable 'opt'
parse.c:14: warning: unused variable 'cmt'
parse.c:14: warning: unused variable 'arg'
parse.c:10: warning: unused variable 'i'
parse.c:10: warning: unused variable 'line_number'
make[2]: *** [sudosh.o] Error 1
I know the proper fix is for the author to fix the code, but I want to work around this problem in the short term. I need a working RPM.
It looks like either ./configure or autoconf is automatically adding the -Werror flag. How can I disable the -Werror flags for my builds, short of editing the Makefile myself?
Update in response to @pwan’s answer:
The .spec file is pretty generic, and doesn’t specify any special flags:
%build
%configure \
--program-prefix="%{?_program_prefix}"
%{__make} %{?_smp_mflags}
The GCC manual has the solution in 3.8 Options to Request or Suppress Warnings:
So, setting
-Wno-errorthe CFLAGS environment variable did the trick for me. Now that I know what I’m looking for, I can see that Stackoverflow has a wealth of answers: https://stackoverflow.com/search?q=%22-Wno-%22 , specifically how to disable specific warning when -Wall is enabled.In my specific case, the build was failing due to ‘warning: unused variable”, and I can suppress those specific warnings with
-Wno-unused-variable.Since I’m using rpmbuild, I need to put this in the .spec file as suggested by @pwan. The only way I could figure this out was to:
Build the rpm once:
Search for the CFLAGS which is generated by
./configureAnd manually append these CFLAGS to my .spec file, into the `%configure% section:
The above is a little hack-ish, because if the ./configure script is changed upstream I may need to re-adjust the CFLAGS in my .spec file.