Clang+LLVM static library linking error on Windows - Why would the symbols be different?

流过昼夜 提交于 2019-12-24 22:11:30

问题


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> 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.

-Here is an example-

Linker error =>

*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

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

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

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

... 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 << Error Message

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

Why is it that these do not match?

Thanks


回答1:


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.

*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.



来源:https://stackoverflow.com/questions/23710994/clangllvm-static-library-linking-error-on-windows-why-would-the-symbols-be-di

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!