使用链接到静态库的 DLL
我正在尝试在 Visual C++ 中构建一个解决方案,其中我有一个引用我创建的 DLL 项目的前端项目。在 DLL 项目中,我链接到一个具有静态对象和定义的静态库(我尚未编写)。一切都构建得很好,但我遇到了链接问题。
我有几个问题。首先,我应该只获取我在前端引用的未导出对象的未解析符号,对吗?我希望 DLL 成为静态库的唯一接口,并且不要在前端直接引用它的任何部分,但我从这个库中得到了许多未解析的符号。这些符号似乎是 #included 的,并且至少有一些符号没有直接由 DLL 项目链接。我怀疑这与静态库中的静态声明有关,但我该如何处理这些?
一些未解决的符号错误:
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: __thiscall SharkException::SharkException(char const *,int,char const *)" (??0SharkException@@$$FQAE@PBDH0@Z)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: static class Bernoulli Rng::coinToss" (?coinToss@Rng@@2VBernoulli@@A)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall ChromosomeT<bool>::operator<(class Chromosome const &)const " (??M?$ChromosomeT@_N@@$$FUBE_NABVChromosome@@@Z)
I'm trying to build a solution in Visual C++ where I have a front-end project that references a DLL project that I created. In the DLL project I link to a static library (that I have not written) that has static objects and definitions. Everything builds fine but I have linking problems.
I have a couple of questions. First, I should only get unresolved symbols for objects that I reference in the front-end that are not exported, right? I want the DLL to be the only interface to the static library and do not directly reference any part of it in the front-end, and yet I get a number of unresolved symbols from this library. There symbols seem to be #included and at least some not directly linked by the DLL project. I suspect it has to do with the static declarations in the static lib but how can I deal with these?
Some of the unresolved symbol errors:
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: __thiscall SharkException::SharkException(char const *,int,char const *)" (??0SharkException@@$FQAE@PBDH0@Z)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: static class Bernoulli Rng::coinToss" (?coinToss@Rng@@2VBernoulli@@A)
2>AnalysisVis.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall ChromosomeT<bool>::operator<(class Chromosome const &)const " (??M?$ChromosomeT@_N@@$FUBE_NABVChromosome@@@Z)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导出的符号被破坏。如果静态库是使用与您正在使用的不同的编译器(或编译器版本)编译的,则应用程序期望看到的符号可能是使用不同的名称修改方案在静态库中定义的。您可以使用以下命令获取静态库中使用的名称修改,然后将其与错误消息中的名称进行比较:
顺便说一句,使用静态库的 DLL 是否可以使用与您的应用程序/解决方案相同的编译器进行干净的编译?
The exported symbols are mangled. If the static lib was compiled using a different compiler (or compiler version) than the one you are using, it is possible that the symbols your application is expecting to see were defined in the static lib using a different name mangling scheme. You can use the following command to get the name mangling used in the static lib and then compare it to the one in the error message:
BTW, does the DLL that uses the static lib compiles cleanly with the same compiler your application/solution does?