Is there a gcc option that discards the -g flag?

I am creating a package that provides a lot of makefiles, each makefile is hard-coded aside, something like

CFLAGS = -g -O2 -Wall ... CXXFLAGS = -g -O2 -Wall ... 

I want to abandon the -g option, but I do not want to edit all the makefiles (not even automatically using sed or something like that). configure script that comes with the package does not have the enable / disable debug option, but I can pass the CFLAGS and CXXFLAGS and combine their values โ€‹โ€‹with the CFLAGS and CXXFLAGS respectively which include the -g option.

Is there an option that discards -g in case it is specified? Sort of

 gcc -option-im-looking-for -g file.c -o file 

Will build a binary file without debugging symbols. I do not want to split the binary, I want it to be created split.

+6
source share
3 answers

You can negate the effect of -g by adding -g0 . Statement

 gcc -g -g0 foo.c -o file.o 

will create a binary identical to the one received by saying

 gcc foo.c -o foo.o 

Quoting man gcc :

  -glevel ... Level 0 produces no debug information at all. Thus, -g0 negates -g. 
+9
source

You do not need to edit make files. Just override the variables on the command line:

 $ cat Makefile CFLAGS = -g -Wall all: echo $(CFLAGS) $ make echo -g -Wall -g -Wall $ make CFLAGS=-Wall echo -Wall -Wall 
+1
source

Since CFLAGS is a bash variable, you can use the template replacement $ {var / Pattern / Replacement} with something like $ {CFLAGS / -g //} to remove -g. Check Replacement Parameters

0
source

Source: https://habr.com/ru/post/956554/


All Articles