views:

65

answers:

2
+1  A: 

In theory you could build just one library if all the external headers for the library (ie the ones pulled in by the client) don't use #ifdef _DEBUG (or any other macro that may be defined in a debug build but not a release build.

Consider a case like this:

// file: mylib.h
struct A {
   int member1;
   int member2;
   #ifdef _DEBUG
     int extraDebugOption;
   #endif
};

In this case, if you were to link the library into a debug build of your own product then A will have a different size to the release build, which means you're going to have some pretty horrendous memory corruption bugs to track down (been there...).

EDIT: Forgot to mention, you should make your one configuration a Release configuration so that you don't end up with any references to the debug CRT, and also so the library is optimised. As lsalamon points out, creating a pdb file and saving this along with your .lib file will be useful in the future for debugging.

the_mandrill
And how should I deal with `/NODEFAULTLIB` warnings when using library build as `Debug` in my `Release` app?
HardCoder1986
Probably the safest way would be to statically link against the release runtime.
the_mandrill
+1  A: 

To include debug info at release version use this configuration :
C/C++->General->Debug Information Format: Program Database (/Zi)
and
Linker->Debugging->Generate Debug Info : Yes (/DEBUG)

lsalamon
These settings are default for `vc90`, as far as I remember.
HardCoder1986
For the release configuration too? (since the OP should probably be building effectively a release configuration of this library)
the_mandrill