3

I'm building a project in VS2015 that uses 3rd party libraries. The 3rd party library I'm using is supposed to be VS2015 (x64) compatible, so it should be compatible with my project. My project settings also have "Ignore Default Libraries" set to NO.

Everything builds find except for a linker error I get right at the end, caused by the 3rd party library:

LNK2001 unresolved external symbol "__declspec(dllimport) char const * __cdecl std::_Winerror_map(int)" (__imp_?_Winerror_map@std@@YAPEBDH@Z)

I have no idea which .lib this "_Winerror_map" function is contained in, but I've managed to track down the source code location:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\crt\src\stl\sysError.cpp

I tried simply including that file in my project, but I get the following error:

Error   C2491   'std::_Winerror_map': definition of dllimport function not allowed

How do I figure out which default lib this source file was included in?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Tyson
  • 1,226
  • 1
  • 10
  • 33
  • Looks like there are MS tools for it: https://stackoverflow.com/questions/437432/is-there-a-way-to-find-all-the-functions-exposed-by-a-dll – Zakir Jun 01 '17 at 00:28
  • Normally there is no way to tell what library you should include. Normal way is to search inside documentation. Next search source code and try to find what header file imports needed function then correlate it with correct lib. You can also try to search in all your libs using OS dependent tools but in extreme situations (like you do not have lib on your machine) it's no way to tell what lib you need to link. – Logman Jun 01 '17 at 00:39
  • Make sure you're building a C++ application (and not a C application) and that you're linking with the DLL version of the runtime library (/MD option). Your undefined symbol is defined in the standard Microsoft C++ runtime import library that all C++ applications are normally linked with. – Ross Ridge Jun 01 '17 at 00:56

1 Answers1

0

When building on Windows, there are a number of different build flavours (e.g. dll vs static) and build types (debug vs release) and platforms (x86, x64).

These create a number of complexities to the compilation process, which Microsoft have tried to fix using a pragma

 #if defined( _DEBUG )
 #   pragma comment ( lib, "steves_debug.lib") 
 #else
 #   pragma comment ( lib, "steves_release.lib" )
 #endif

The comment (lib describes information which is added to the .obj to ensure that the correct libraries are added automatically to the link command.

This can be overridden by linking with /nodefaultlib. This is a bad idea, as some of these variants rely on code running before main, or dllMain to ensure they are leak free.

The MSVC runtime dlls are normally pulled in by supply /MT[d] /MD[d] during the compilation phase.MSDN : /MT /MD

mksteve
  • 12,614
  • 3
  • 28
  • 50