Determing whether Debug or Release is active

Hi

Is there any way to know if the current configuration is debug or release? What I want to do is something like

  
  
#ifdef DEBUG  
//some special code  
#else  
//some other code  
#endif  
  

It should work on linux and os x.

thanks, philip

interesting question! This is at least a question on the topic: http://stackoverflow.com/questions/2249282/c-c-portable-way-to-detect-debug-release

Hmm, I tried NDEBUG and it didn’t work on linux with the make file. But according to the comments on your link, it looks like this is something that has to be defined in the of project templates if it should work reliably, so it’s probably not the best idea to use it…?

I don’t know. Maybe someone else (arturo?) knows a way…

maybe this is a potentially viable approach: http://forum.openframeworks.cc/t/ofxconnexion/4501/4

Thanks. I just tried that with linux. Looks like it’s XCode only… :frowning:

yeah, sure, it’s about an xcode config file, after all. what I meant is the approach in general, i.e. defining preprocessor defines involving the executable name or something externally (in your case: in the makefile). for example, like this: http://stackoverflow.com/questions/1887464/c-preprocessor-variable

Ah ok. I misunderstood you then…

Yes, I have solved it with adding a c preprocessor like -DVARIABLENAME . This works fine and I don’t mind commenting it out in the make.config, depending on what “target” I want to compile. But this is a little bit of a disadvantage of the makefile approach compared to a project like for example in XCode. There I could just add -DVARIABLENAME to the debug target and that’s it…

you could adapt the makefile to add -DVARIABLENAME depending on the make target (Debug/Release), and then maybe add a flag (ExtraDebugProcessing or whatever) controlling that extra behaviour in make.config, no?

I’m in the process of refactoring the Makefiles, this can be really usefull i can add a -DOF_DEBUG in the debug. I was also thinking on adding debug and release variants of the CFLAGS in config.make

haha just search the forum for this again and forgot that I already asked.

@arturo Have you implemented this in the meantime? Can be useful when developing addons

no but i also discovered recently that there’s a define that is standard for this, NDEBUG. if it’s 1 then asserts won’t halt the program among other stuff, we should add it to the release target

1 Like

I’m not sure if this has gotten a formal solution yet, but I couldn’t find it, so I just created a pull request with my personal solution, which lets you create Debug-specific preprocessor macros in config.make like this;

PROJECT_DEFINES_DEBUG=DEBUG

right now when using makefiles or qtcreator DEBUG is defined when using the debug target and NDEBUG when using release

This seems to be no more valid. I’m try to include or not pieces of code in release or debug builds but none of the following env vars seems to work:

  • DEBUG
  • NDEBUG
  • RELEASE
  • PRODUCTN

I’m using the latest stack:

  • of_11
  • xcode 11

any suggestion about this?