Question

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.

Was it helpful?

Solution

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:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top