29

My project compiled with -g option instead of -g3, which means that I can't expand macros in gdb. I want to add the -g3 flag to GCC, but I don't want to modify the makefile, I just want to add this flag via the Make command line.

How can I do it?

double-beep
  • 5,031
  • 17
  • 33
  • 41
wangshuaijie
  • 1,821
  • 3
  • 21
  • 37

1 Answers1

51

That depends on what the Makefile does/how it was written. It might not be possible.

If your Makefile is reasonably "standard", then this should work:

make CFLAGS="-g3 ..."

If it's for C++:

make CXXFLAGS="-g3 ..."
Mat
  • 202,337
  • 40
  • 393
  • 406
  • I understand your point, thank you! – wangshuaijie Sep 25 '11 at 07:11
  • 8
    yet another question, the variable CFLAGS may be already defined in my makefile, I just want to append the -g3 to it, not to assign it a new value, how can I do? Does it have a grammar like "CFLAGS+="-g3"" or something else? – wangshuaijie Sep 25 '11 at 07:13
  • 5
    @wangshuaijie I this that make CFLAGS:=$(CFLAGS) -g3 would append them – Shlomi Zadok Sep 17 '13 at 11:49
  • composes conveniently with `-Dblabla`: http://stackoverflow.com/a/13127824/1959808 – 0 _ Nov 12 '15 at 08:58
  • 1
    what is the meaning of "reasonably standard" ? Does that mean that the symbol CFLAGS must be defined in the Makefile and in that case using the command line parameter will prepend `-g3` to it? – 463035818_is_not_an_ai Jan 12 '18 at 12:54
  • Just to be 100% clear, regular warning flags can go inside of the 'CFLAGS' call too? I'm trying to use WError in this example and it's not working -- my command line looks like this: ` make CFLAGS="-O0 -g3 -Wall -Wextra -Wpedantic -Werror" -C <.... rest of it here....>` – Raleigh L. Oct 25 '22 at 00:09
  • @RaleighL. that syntax did work for me (for a different warning flag). – Tgr Jan 16 '23 at 05:50