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!
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.
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).
$@ 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.
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.
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.
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 ”
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.
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 ..."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With