Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass values during compilation with g++ using -DN flag

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

like image 549
Soroosh Khoram Avatar asked Mar 11 '13 12:03

Soroosh Khoram


People also ask

What is flag in g ++ compiler?

(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.

How do you pass a flag in Makefile?

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.

What is flag in compiling?

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.

What is the usage of G flag while using it with gcc for compiling C code?

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.


1 Answers

-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:

  • GCC Preprocessor Options
like image 164
Kun Ling Avatar answered Sep 17 '22 02:09

Kun Ling