Unresolved symbol errors within DLL

牧云@^-^@ 提交于 2020-01-13 09:11:23

问题


For background, I have come across this porting a medium-sized linux codebase (compiling into a giant .so) to x64 windows (compiling into a .dll). I have had linker trouble.

As a minimal testcase, if I create a Visual Studio project from just the following file:

#include <Windows.h>
#include <Dbghelp.h>

void do_stuff(char const * s)
{
  char buffer[4096];
  long int len = UnDecorateSymbolName(
    s,
    buffer,
    sizeof(buffer),
    UNDNAME_COMPLETE);
}

And I set the project type to DLL and build it, I get an error "LNK2001: Unresolved external symbol __imp_UnDecorateSymbolName". That is, the file compiles properly, but fails to link into a dll.

I think the goal is for my dll to link to dbghelp.dll, especially since (at least on my system) there is no such file as a dbghelp.lib. So why is it trying to resolve that symbol now, rather then when my DLL is loaded into an application? And why can't it see that function anyhow?

To be clear, I have confirmed that I am building the x64 DLL, and that the dbghelp.dll in C:\Windows\System32 is x64.


回答1:


Linking to shared libraries, DLLs in Windows-speak, requires the following:

  1. A header file at compile time: Dbghelp.h.
  2. An import library at link time: Dbghelp.lib.
  3. A DLL at runtime: Dbghelp.dll.

You clearly have 1 and 3 and are missing 2. The Windows SDK that comes with Visual Studio includes the import library. But you need to add it as an additional dependency in your project's linker options.

Like this:



来源:https://stackoverflow.com/questions/9522834/unresolved-symbol-errors-within-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!