Automatically specify .LIB in header for Visual Studio 2008 C ++

Is it possible to automatically link the C ++ static library in Visual Studio 2008? Or is there an improvement in using the standard approach?

I am developing a set of C ++ libraries, and linking / testing them is quite a pain. The usual approach is to specify .lib files in test clients, but now the list has become quite large (my own libraries, opencv, boost and others), and I always skip something when switching between debug and release modes, gpu and non-gpu etc. When I open the linker in the project properties, the list scrolls for some time.

I was hoping I could automatically indicate that if client # includes that the project should also reference the specified .lib (debug / release). Is this possible or is there an alternative approach that will help manage communication with minimal user interaction?

+5
source share
1 answer

Use #pragma comment(lib, "name_of_the_library.lib"). Other useful options for #pragma commentcan be found on the MSDN page .

Regarding the configuration of Debug vs. Release: the _DEBUG preprocessor macro is usually used to distinguish it. Visual C ++ - the header certainly uses it for the same purpose as you want; for example, this is from a VC ++ 2010 file use_ansi.h:

#ifdef _DEBUG
#pragma comment(lib,"msvcprtd")
#else   /* _DEBUG */
#pragma comment(lib,"msvcprt")
#endif  /* _DEBUG */
+5
source

All Articles