使用链接到静态库的 DLL

发布于 2024-10-06 15:22:29 字数 886 浏览 4 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2024-10-13 15:22:29

导出的符号被破坏。如果静态库是使用与您正在使用的不同的编译器(或编译器版本)编译的,则应用程序期望看到的符号可能是使用不同的名称修改方案在静态库中定义的。您可以使用以下命令获取静态库中使用的名称修改,然后将其与错误消息中的名称进行比较:

>pushd <path_to_msvc_dir>\Microsoft Visual Studio X.0\VC\bin
>dumpbin /all [static_lib_path] > out.txt
>type out.txt | find /I "SharkException"
>type out.txt | find /I "coinToss"
>type out.txt | find /I "ChromosomeT"

顺便说一句,使用静态库的 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:

>pushd <path_to_msvc_dir>\Microsoft Visual Studio X.0\VC\bin
>dumpbin /all [static_lib_path] > out.txt
>type out.txt | find /I "SharkException"
>type out.txt | find /I "coinToss"
>type out.txt | find /I "ChromosomeT"

BTW, does the DLL that uses the static lib compiles cleanly with the same compiler your application/solution does?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文