Is it possible to automatically link a c++ static library in Visual Studio 2008? Or, is there an improvement to use from 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 the .lib files in the test clients, but now the list has grown quite large (my own libs, opencv, boost, and others) and I'm always missing something as I switch between debug and release modes, gpu and non-gpu, etc. When I open the linker in project properties the list scrolls on for some time.
I was hoping that I could automatically specify that if a client #includes something that the project should also link to a specified .lib (debug/release). Is this possible or is there an alternate approach that will help manage linkage with minimal user interaction?
Place your caret on the first line of any C# or Visual Basic file. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Add file header. To apply the file header to an entire project or solution, select Project or Solution under the Fix all occurrences in: option.
How to Add an External C++ Library to Your Project Using the Visual Studio IDE. Step 1: Go to the website of the library. Step 2: Download the zip file that contains all the code. Step 3: Unzip the zip file to your computer.
#pragma comment( lib, "emapi" ) The following pragma causes the compiler to place the name and version number of the compiler in the object file: C Copy.
Use #pragma comment(lib, "name_of_the_library.lib")
. Other useful options for #pragma comment
can be found at the MSDN page.
With regard to Debug vs. Release configuration: usually a _DEBUG preprocessor macro is used to distinguish. Visual C++ header certainly use it for the same purpose as you want; e.g. this is from VC++ 2010 use_ansi.h
file:
#ifdef _DEBUG
#pragma comment(lib,"msvcprtd")
#else /* _DEBUG */
#pragma comment(lib,"msvcprt")
#endif /* _DEBUG */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With