gcccommand-linepreprocessor-directivegnustep

Negate previous -D[efine] flag for GCC


Under GNUStep on Arch Linux, I'm running into an interesting error on a fresh install.

Using my build system I run

gcc `gnustep-config --debug-flags` [other command line args]

in order to build up the command line per the operating system's necessary flags.

This works fine under Ubuntu, but on Arch Linux I'm getting a rather random error:

/usr/include/features.h:328:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]

Well, gnustep-config --debug-flags spits out the following:

-MMD -MP -D_FORTIFY_SOURCE=2 -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -pthread -fPIC -g -DDEBUG -fno-omit-frame-pointer -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -march=x86-64 -mtune=generic -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -fgnu-runtime -fconstant-string-class=NSConstantString -fexec-charset=UTF-8 -I. -I/home/qix/GNUstep/Library/Headers -I/usr/include -D_FORTIFY_SOURCE=2 -I/usr/include -I/usr/include -I/usr/include -I/usr/lib/libffi-3.1/include/ -I/usr/lib/libffi-3.1/include -I/usr/include/libxml2 -I/usr/include/p11-kit-1

As well, I wish not to have optimizations on my debug builds (and later on I even override GNUStep's -g parameter to -g2).

Is there a way to explicitly undefine -D_FORTIFY_SOURCE later on in the command line, after the call to gnustep-config?

For example, something like

gcc `gnustep-config --debug-flags` -U_FORTIFY_SOURCE ...

where the -U undefines the previously defined macro?

Something to mention; I have -Werror enabled on purpose, and I'd like to keep it.


Solution

  • For now, using sed to work around this works. It appears this is a known issue with _FORTIFY_SOURCE causing issues, and there isn't a straightforward fix.

    `gnustep-config --debug-flags | sed 's/-D_FORTIFY_SOURCE=2//g'`