Reputation: 23
I am experiencing technical difficulties with preprocessor directives :
#ifdef, #define
I have a program built by a Makefile, and I have 2 options two build it : standalone or embedded.
I did something like :
#ifdef _mdimode_
//code for embedded
#else
//code for standalone (default)
#endif
And in my main file when I compile in embedded purpose I wrote a :
#define _mdimode_
But it seems that g++ does not recognize or understand it. It always go in the else and never compile the code for embedded version.
Infos:
GNU Make 3.82
g++ (GCC) 4.6.1 20110908 (Red Hat 4.6.1-9)
file suffix : .C
Upvotes: 1
Views: 641
Reputation: 6649
This is a bit of a guess without more information. I assume the code is in a different file than the main file. If this is so then the #define
doesn't propagate to that part of the project. You would have to set it in the file that contains the code, or in a header that is #include
d in it.
You can also choose to set the #define
in the options of the compilation command:
g++ -c -D_mdimode_ mycode.C
Upvotes: 1