DLL中未解决的符号错误 [英] Unresolved symbol errors within DLL

查看:225
本文介绍了DLL中未解决的符号错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于背景,我遇到了将中型linux代码库(编译成巨大的.so)移植到x64 Windows(编译成.dll)的过程.我遇到了链接器问题.

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.

作为最小的测试用例,如果我仅从以下文件创建一个Visual Studio项目:

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);
}

然后将项目类型设置为DLL并进行构建,我收到一个错误"LNK2001:无法解析的外部符号__imp_UnDecorateSymbolName".也就是说,文件可以正确编译,但是无法链接到dll.

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.

我认为目标是使我的dll链接到dbghelp.dll,尤其是因为(至少在我的系统上)没有dbghelp.lib这样的文件.那么,为什么现在尝试解析该符号,而不是当我的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?

为清楚起见,我已经确认我正在构建x64 DLL,并且C:\ Windows \ System32中的dbghelp.dll是x64.

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

推荐答案

要链接到共享库,以Windows而言,DLL需要进行以下操作:

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

  1. 编译时的头文件:Dbghelp.h.
  2. 链接时的导入库:Dbghelp.lib.
  3. 运行时DLL:Dbghelp.dll.
  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.

您显然有1和3,但缺少2.VisualStudio附带的Windows SDK包含导入库.但是您需要在项目的链接器选项中将其添加为附加依赖项.

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.

赞:

这篇关于DLL中未解决的符号错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆