I've heard that you can set values in your c++ program during compilation using g++'s -DN flag. Can anybody explain how? Thank you
(debug) Inserting the `g' flag tells the compiler to insert more information about the source code into the executable than it normally would. This makes use of a debugger such as gdb much easier, since it will be able to refer to variable names that occur in the source code.
The only way of doing that is to edit the makefile to change the options. There is no convenient way to override the options without modifying the makefile . This is where make flags come into play. Flags in make are just variables containing options that should be passed to the tools used in the compilation process.
Compile-time flags are boolean values provided through the compiler via a macro method. They allow to conditionally include or exclude code based on compile time conditions. There are several default flags provided by the compiler with information about compiler options and the target platform.
In general you pass -g to gcc (which really is a front-end for the whole compilation process and not just a compiler) and it will take care of it. Show activity on this post. then you will find the size of the file example1 is greater than the size of example because -g flag enabled the debugging information.
-DXXX
flag is just like adding #define XXX
. So -DN=2
is just like #define N 2
.
And you can pass values during compilation using this flag.
Reference:
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