LNK2019问题 [英] LNK2019 problem

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

问题描述

我有一个 LNK2019 问题尝试在我的项目中使用某些 DLL 时.

I have a LNK2019 problem when trying to use some DLL in my project.

详情:

  1. 我有一个名为 dll1 的 DLL 项目;编译得很好(使用 __declspec(dllexport))以便导出 dll1 中的类(用于 dll2 使用).
  2. 我有另一个使用 dll1 功能的 DLL 项目 dll2.我在项目属性的链接器输入中指定了 *.dll1.lib 文件路径,并引用了 dll1 *.h 文件.在这一点上,一切都需要正常工作.(我认为..)
  3. 在编译 dll2 时,我收到一个 LNK2019 错误,告诉我找不到 dll1 中引用的某些方法.(dll1中的这个方法是静态方法.)
  1. I have a DLL project called dll1; that compiled just fine (using __declspec(dllexport)) in order to export the class inside dll1 (for dll2 usage).
  2. I have another DLL project dll2 that uses dll1's functionality. I specified the *.dll1.lib file path inside the linker input in the project's properties and gave reference to dll1 *.h files. At this point everything needs to work fine. (I think..)
  3. When compiling dll2, I get a LNK2019 error that tells me can't find some method referenced in dll1. (This method in dll1 is a static method.)

为什么会出现此错误?

推荐答案

关于 LNK2019 的 MSDN 页面 已经给出了很多为什么会发生这个错误的例子.为了追踪到底发生了什么,我建议这样做:

The MSDN page about LNK2019 already gives plenty of examples why this error occurs. In order to trace down what exactly is going on, I recommend doing this:

  1. 在链接器抱怨破坏名称的符号上运行 undname(请参阅 查看装饰名称 以了解如何运行 undname 的示例.
  2. 运行 dumpbin/EXPORTS(或使用图形Dependency Walker)来获得DLL1 导出的所有符号的列表.
  1. Run undname on the symbol which the linker complains about to demangle the name (see Viewing Decorated Names for an example how to run undname).
  2. Run dumpbin /EXPORTS (or use the graphical Dependency Walker) to get a list of all symbols exported by DLL1.

所以现在您有了链接器尝试查找的符号的解构名称,并且您有了 DLL1 导出的符号列表.并且链接器告诉您它在列表中找不到请求的符号.以下是关于正在发生的事情的两个想法:

So now you have the demangled name of the symbol which the linker tries to find, and you have the list of symbols which are exported by DLL1. And the linker tells you that it cannot find the requested symbol in the list. Here are two ideas about what's going on:

  1. 您会看到 DLL1 在其导出列表中包含已损坏的符号,但并不完全是链接器所抱怨的已损坏的名称.当您导出的函数几乎与链接器期望的相同时,就会发生这种情况.可能是您在某处缺少const",或者调用约定不同.
  2. 您会看到 DLL1 没有导出任何看起来像链接器期望的符号.这表明 DLL1 的声明中缺少某些 __declspec(dllexport).
  1. You see that DLL1 has the demangled symbol in its export list, but not exactly the mangled name which the linker complains about. This can happen when the function you export is almost the same which the linker expects. It might be that you have a 'const' missing somewhere, or the calling convention is different.
  2. You see that DLL1 doesn't export any symbol which looks like what the linker expects. This suggests that some __declspec(dllexport) is missing in the declarations of DLL1.

这篇关于LNK2019问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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