Home > C++, General > How to mark a binary file as Debug/Release in C++

How to mark a binary file as Debug/Release in C++

As all probably know, while developing a project, we compile it using Debug mode, whereas compiling for deployment purpose is performed in Release mode. Still, sometimes we need to combine Debug and Release binaries. For instance one might want to compile in Debug, but to use 3rd party’s binaries in Release. In this case, we’d like to have some simple way to distinguish binary files according to thier compiling type.

In some projects this goal is achieved by adding a character “d” in the end of Debug binary file. E.g. file named “Engine.dll” is called “Engined.dll” in Debug version. It works, but it is no plesant, because the project must have two different structures: one for Debug and another for Release.

We’d like to find some way, to see binary file’s type on its property (which is opened by right click on file), as it is shown later. Fortunately, this way was found (thanks Max).

In order to acheive the goal, one should follow the next steps:

1) Define inside “project settings -> resources -> general” some new macro to be identified in debug mode – for instance NDEBUG. Note that you can not use “regular” defined DEBUG, because it is not defined in resources, which we are going to use.

2) Define some macro to be used in code, e.g. CUR_COMPILE_MODE in the next way:

#if defined(NDEBUG)
               #define CUR_COMPILE_MODE               “Flavor=Debug”
               #define CUR_COMPILE_MODE               “Flavor=Retail”

3) Add next line to the resources file (*.rc)

               VALUE “Comments”,  CUR_COMPILE_MODE

Now, when “right click -> properties -> version” is pressed, in “comments” paragraph appears the required characteristic, depends on our build type:

Note, that “CUR_COMPILE_MODE” definition should not be inserted into resources file, because parts of resoures file are auto-generated, and our definition could be deleted. The definition should be rather placed inside some header file (*.h).

Categories: C++, General Tags: ,
  1. Vlad
    June 15th, 2011 at 15:54 | #1

    Did you try it on Windows 7?

  1. No trackbacks yet.