C++ Library Does Not Link in Release Configuration (VS2010)
I've been trying to get static libraries (.lib
files) to work in VS2010, and I have it working perfectly in the debug configuration. When I try to compile it under the release configuration, however, I get the error error C1083: Cannot open include file: 'Library.h': No such file or direc开发者_StackOverflow中文版tory
.
Here's the current scenario:
- I have a
.lib
file and a.h
file in a folder on my desktop calledStatic Library
. - I have the INCLUDE environment variable pointed to the aforementioned folder (so I can use
#include <Library.h>
). - I have the LIB environment variable pointed to the aforementioned folder as well.
- I have added the
.lib
file as an additional dependency and set the directory for additional dependencies.
My source code for the test program looks like this:
#include <iostream>
#include <Windows.h>
#include <Library.h>
int main()
{
std::cout << Library::GetValue(); // Returns 123.
Sleep(10000);
return 0;
}
What could I be doing incorrectly?
Not sure about VS2010... but the debug and release modes probably have different library settings...
You can inform the compiler to link thru code by specifying the following
#pragma comment(lib, "library.lib") // no ; is needed
That will make it link in both debug and release
精彩评论