Windows上的Clang + LLVM静态库链接错误-为什么符号会不同? [英] Clang+LLVM static library linking error on Windows - Why would the symbols be different?

查看:339
本文介绍了Windows上的Clang + LLVM静态库链接错误-为什么符号会不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照llvm网站上的说明编译clang和llvm之后,我尝试链接到测试应用程序中已构建的静态库.所有代码都是使用VS工具集的v110构建的.我收到类型为错误LNK2001"和错误LNK2019"的链接器错误.

After compiling clang and llvm following the instruction on the llvm website I try linking to the built static libs in a test app. All code is built with v110 of the VS toolset. Im getting linker errors of type "error LNK2001" and "error LNK2019".

该应用程序似乎将库放到存储桶中以进行符号解析.通过详细的链接器输出,我可以看到它们只是被关闭了:

The app appears to put the libs in the bucket for symbol resolution. With verbose linker output i can see that they are just being dismissed:

1>未使用的库: ... 1> C:\ Sdk \ llvm \ Debug \ lib \ clangTooling.lib ...

1> Unused libraries: ... 1> C:\Sdk\llvm\Debug\lib\clangTooling.lib ...

深入研究发现错误消息中的符号与库中的符号并不完全相同.

Digging a little deeper i have found that the symbols in the error message and the ones in the libs are not quite the same.

-这里是一个例子-

链接器错误=>

*无法解析的外部符号"public:int __cdecl clang :: tooling :: ClangTool :: run(class clang :: tooling :: ToolAction )"(?run @ ClangTool @ tooling @ clang @@函数main

*unresolved external symbol "public: int __cdecl clang::tooling::ClangTool::run(class clang::tooling::ToolAction )" (?run@ClangTool@tooling@clang@@QEAAHPEAVToolAction@23@@Z) referenced in function main

...给出" ?run @ ClangTool @ tooling @ clang @@ QEAAHPEAVToolAction @ 23 @@ Z "作为符号名称.

...giving "?run@ClangTool@tooling@clang@@QEAAHPEAVToolAction@23@@Z" as the symbol name.

现在在我的构建版本的clangTooling.lib =>

Now using "dumpbin /SYMBOLS" on my built version of the clangTooling.lib =>

* FDA 00000000 UNDEF notype()外部| ?run @ ClangTool @ tooling @ clang @@ QAEHPAVToolAction @ 23 @@ Z(公共:int __thiscall clang :: tooling :: ClangTool :: run(class clang :: tooling :: ToolAction ))

*FDA 00000000 UNDEF notype () External | ?run@ClangTool@tooling@clang@@QAEHPAVToolAction@23@@Z (public: int __thiscall clang::tooling::ClangTool::run(class clang::tooling::ToolAction ))

...我可以看到我正在寻找的符号称为 " ?run @ ClangTool @ tooling @ clang @@ QAEHPAVToolAction @ 23 @@ Z "

... i can see the the symbol im looking for is called "?run@ClangTool@tooling@clang@@QAEHPAVToolAction@23@@Z"

在地址的开头附近有一个非常细微的差别.在这里,它们再次并排比较.

There is a very subtle difference near the beginning of the address. Here they are again side by side for comparison.

?run @ ClangTool @ tooling @ clang @@ QEAAHPEAVToolAction @ 23 @@ Z<<错误消息

?run@ClangTool@tooling@clang@@QEAAHPEAVToolAction@23@@Z << Error Message

?run @ ClangTool @ tooling @ clang @@ QAEHPAVToolAction @ 23 @@ Z<<垃圾箱输出

?run@ClangTool@tooling@clang@@QAEHPAVToolAction@23@@Z << Dumpbin Output

为什么这些不匹配?

谢谢

推荐答案

因此,事实证明,我构建的LLVM/clang库为32位,而我的测试项目为64位.我已经成功地使用32位二进制文​​件构建了一个测试项目.关于此答案的注释在C ++中未解决的外部问题: Visual C ++修改方法的签名与dll中修改的方法不同详细描述了该问题.

So it turns out the LLVM/clang libraries I had built were 32 bit while my test project was building 64 bit. I have successful built a test project using 32 bit binaries. The notes on this answer Unresolved Externals in C++: Visual C++ mangles method signature differently from mangled method in dll describe the issue in more detail.

*对于任何其他与LLVM库链接的人,请注意. LLVM/clang的CMake文档(可在此处找到 http://llvm.org/docs/CMake.html )听起来像在64位系统上默认为64位.在Windows7 64位/VisualStudio11上(至少在我的计算机上)不是这种情况.我还没有从CMake菜单中找到支持64位编译的选项.目前看来,唯一的选择就是嵌入到32位应用程序中.

*Note for anyone else looking into linking with LLVM libs. The CMake documentation for LLVM/clang (found here http://llvm.org/docs/CMake.html) makes it sound like it defaults to 64 bit on a 64 bit system. On Windows7 64bit/VisualStudio11 (at least on my machine) this isnt the case. I haven't yet found an option to support 64 bit compilation from the CMake menu. For now it seems the only option is to embed into 32 bit apps.

这篇关于Windows上的Clang + LLVM静态库链接错误-为什么符号会不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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