User forums > Using Code::Blocks
A little help with Compiler Settings > Defines
lejar:
I have several build targets that reference the same code and I would like certain build targets to not compile a section of the shared code. (The server target should compile everything and the client target should not compile a specific section of code.) Under the build options for the server target, I've gone to compiler settings > #defines and entered the following:
--- Quote ---"SERVERTOPOLOGY=1"
--- End quote ---
My code looks like this:
--- Code: ---general code
#if SERVERTOPOLOGY==1
code for the server
#endif
more general code
--- End code ---
Unfortunately, I can't seem to get this to work. The server target does not compile the code inside of the #if statement. I've also tried single quotes, and leaving the quotes away for the define. I've also tried replacing the #if SERVERTOPOLOGY==1 part with #ifdef SERVERTOPOLOGY to no avail.
Perhaps someone can give me a little insight into my problem?
zabzonk:
The define should not be in quotes. If you do:
SERVERTOPOLOGY=1
then both the #ifdef and #if directives should work. Oh, and make sure you are defining it it for the right target.
lejar:
Thanks for the input, Neil. I had tried it without the quotes. Checking the target proved interesting, though. I am using a virtual target to build my targets in one click. When I build each target individually, the defines work. When I build using my virtual target, the defines do not work. Is this a bug or a feature?
zabzonk:
I've never used virtual targets before, but I just tried it and it seems to work OK - what build of C::B are you using? Also, you can define it for all real targets by adding it to the top-level target in the tree on the left of the Project build options dialog.
lejar:
--- Quote from: Neil Butterworth on September 29, 2012, 02:50:58 pm ---what build of C::B are you using?
--- End quote ---
I'm using 10.05 rev 0 on Ubuntu 12.04 x64.
--- Quote from: Neil Butterworth on September 29, 2012, 02:50:58 pm --- Also, you can define it for all real targets by adding it to the top-level target in the tree on the left of the Project build options dialog.
--- End quote ---
I need it to be different for individual targets, though.
Navigation
[0] Message Index
[#] Next page
Go to full version