Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: scarphin on April 14, 2011, 11:23:34 am

Title: Constant definitions for debug, release etc
Post by: scarphin on April 14, 2011, 11:23:34 am
Is there any constants defined when a specific build target is chosen? I mean does CB define anything automatically? I'm trying to compile build target specific code like below:

#if defined DEBUG (can be something CB defines)
    do this;
#elif defined RELEASE (same here)
    do that;

I know I can define them manually but I want to use what CB defines if there is any. Thnx...
Title: Re: Constant definitions for debug, release etc
Post by: Jenna on April 14, 2011, 11:42:23 am
Inside C::B the "$target"-variable contains the name of the active build-target.
Title: Re: Constant definitions for debug, release etc
Post by: scarphin on April 14, 2011, 12:09:15 pm
I couldn't think of a way to use it, I guess it won't work when injected into the source like '$target'. So how can I make a constant out of it?
Title: Re: Constant definitions for debug, release etc
Post by: oBFusCATed on April 14, 2011, 12:32:53 pm
I know I can define them manually but I want to use what CB defines if there is any. Thnx...
There are no automatic/automagic defines, you have to add all you defines in project -> build options -> [target] -> compiler -> defines
Title: Re: Constant definitions for debug, release etc
Post by: scarphin on April 14, 2011, 01:48:13 pm
I know I can define them manually but I want to use what CB defines if there is any. Thnx...
There are no automatic/automagic defines, you have to add all you defines in project -> build options -> [target] -> compiler -> defines
Well, I'm not looking for magic, that was what I was looking for. ;) One last question, I've searched but couldn't find and specific information about this. How do I define a constant in project -> build options -> [target] -> compiler -> defines?
Is it like
'#define DEBUG 1'
or just
'DEBUG 1'
or how?
Title: Re: Constant definitions for debug, release etc
Post by: killerbot on April 14, 2011, 02:00:01 pm
either you just define it, aka value doesn't matter :

Code
DEBUG

or you give it a value

Code
DEBUG=1

Title: Re: Constant definitions for debug, release etc
Post by: scarphin on April 14, 2011, 02:16:57 pm
Ok got it. Maybe because I'm a noob but the work u have done with codeblocks still continues to impress me in every detail. ;) Thnx...
Title: Re: Constant definitions for debug, release etc
Post by: killerbot on April 14, 2011, 02:28:36 pm
fyi : the common convention is in the release build to define NDEBUG, and don't define anything in debug build.
Title: Re: Constant definitions for debug, release etc
Post by: scarphin on April 14, 2011, 03:47:39 pm
Yup I know, I guess it's because of the 'assert' macro. ;) Thnx anyway.