简体   繁体   中英

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 directory .

Here's the current scenario:

  • I have a .lib file and a .h file in a folder on my desktop called Static 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM