28

I am debug our project, but I find that the project was compiled with -g ,but not -g3, which means that I can't expand macros in gdb. I want to add -g3 flag to gcc, but I don't want to modify Makefile, I just want to add this flag via Make command line, could anyone tell me how to do it? Thank you!

wangshuaijie
  • 1,759
  • 3
  • 19
  • 36

1 Answers1

50

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
  • 195,986
  • 40
  • 382
  • 396
  • I understand your point, thank you! – wangshuaijie Sep 25 '11 at 07:11
  • 7
    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_a_number Jan 12 '18 at 12:54