tags:

views:

425

answers:

6

Our project is using many static libraries to build the application. How can we make sure we are using release version of libraries in release build of application? we are making mistakes by taking debug library in release application build. I am looking for an elegant way in which I can write a module in that we can check whether a particular library is release or debug and report it if not matching. our application is written in C/C++. (Platform MSVC & GCC)

Thanks in advance Manoj

+2  A: 

Can you not solve this using naming conventions (i.e., foo_rel.a and foo_dbg.a )?

Gilad Naor
A: 

Normally one would distinguish the versions using a slightly different names. For example under debug builds all the libraries are suffixed with a character 'd' before their extension. Ex. commonUtilsd.lib Under release mode the same would be commonUtils.lib. This approach IMHO is simpler and cleaner. In MSVC use can specify the output filename under

Librarian-->General-->Output File

Another recommendation is to have these output files in the configuration directory. i.e. have debug-version in the Debug folder and release-versions under Release folder. Again under MSVC this can be done generically using the $(ConfigurationName) IDE-macro. And attach the right path in the lookup directories during build.

Abhay
+4  A: 

The normal approach is eithr to give the libraries different names or store them in different directories, such as Debug and Release. And if your build is correctly automated, I can't see how you can make mistakes.

anon
A: 

Naming conventions aside, if you're on a unix-like system, you can probably parse the output of:

objdump -g mylib.a

If you only get empty lines or lines starting with object file names, then you have no debug information in the library.

Note that this does not generally mean that the library is "release" or "debug", but it may mean it in your case.

Gilad Naor
+2  A: 

Yes. You can check the Characteristics field of the IMAGE_FILE_HEADER structure of the file. If the library is a release build, then bit 0x0200 (DEBUG_STRIPPED) will be set; on a debug build, it will be clear.

You can find technical information on the PE Format used by Windows EXEs and DLLs, to see how to retrieve that structure, in various places on the 'net (such as here).

Head Geek
+1  A: 

How about having a simple function which returns the version of the library? Return different things based on your build being debug or release. Call that function at the start of your app and report the error.

joelr
so much simpler than all the other garbage suggested.
caspin
yes, good suggestion
Manoj