Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass -g3 flag to gcc via Make command line? [duplicate]

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!

like image 544
wangshuaijie Avatar asked Sep 25 '11 06:09

wangshuaijie


People also ask

How do I pass a flag in makefile?

LDFLAGS. You can use LDFLAGS to pass extra flags to the linker lD . Similar to CPPFLAGS , these flags are automatically passed to the linker when the compiler invokes it. The most common use is to specify directories where the libraries can be found, using the -L option.

How do I pass a macro in makefile?

I usually pass macro definitions from "make command line" to a "makefile" using the option : -Dname=value. The definition is accessible inside the makefile. I also pass macro definitions from the "makefile" to the "source code" using the similar compiler option : -Dname=value (supported in many compilers).

What is $@ in makefile?

$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.

What are the important GCC Flags?

Here are some of the important GCC Flags which might come handy : 1. Name the output file with -o file This flag helps us to specify the name of the final executable produced by GCC. It places the output of the final executable in a file “ file ” as specified along with the flag.

What are the options in GCC command line?

3 GCC Command Options When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The “overall options” allow you to stop this process at an intermediate stage. For example, the -coption says not to run the linker. Then the output consists of object files output by the assembler.

How do I name the output file of a GCC program?

Name the output file with -o file This flag helps us to specify the name of the final executable produced by GCC. It places the output of the final executable in a file “ file ” as specified along with the flag. If the -o flag is not supplied, it stores the output in a file called “ a.out ”

Where do I find compiler flags in GCC?

Documentation for compiler flags is available in the GCC manual. Those flags (which start with -Wl) are passed to the linker and are described in the documentation for ld . -D_GLIBCXX_ASSERTIONS enables additional C++ standard library hardening.


1 Answers

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 ..." 
like image 180
Mat Avatar answered Oct 17 '22 02:10

Mat