简体   繁体   English

Clang,Microsoft链接器和标准库

[英]Clang, Microsoft linker and standard library

I have successfully built Clang with Microsoft C++ and I'm trying to get it to compile a hello world test case; 我已经用Microsoft C ++成功构建了Clang,并且我试图让它编译一个hello world测试用例; it gets as far as generating an object file, linking with the standard library being the remaining stumbling block: 它生成一个目标文件,与作为剩余绊脚石的标准库链接:

hello-202520.o : error LNK2019: unresolved external symbol _printf referenced in function _main
LINK : error LNK2001: unresolved external symbol _mainCRTStartup

There are comments from previous years saying Clang doesn't yet do Windows linking at all, but I get the impression those are outdated, and indeed it does now seem to be able to generate Windows format object files: 前几年有评论说Clang还没有进行Windows链接,但我觉得那些已经过时了,现在它确实能够生成Windows格式的目标文件:

clang -c hello.c
ren hello.o hello.obj
link hello.obj

... doesn't barf, so the file format seems to be correct, but still gets the unresolved external symbol errors. ...没有barf,所以文件格式似乎是正确的,但仍然得到未解决的外部符号错误。 Likely guess is the Microsoft compiler tags its output object files with an indication of the standard library they need to be linked with whereas Clang doesn't, and eyeballing a hex dump of the respective object files seems to confirm this and gives a hint of the linker command line to use: 可能的猜测是Microsoft编译器标记其输出目标文件,并指示他们需要链接的标准库,而Clang没有,并且眼睛看到相应目标文件的十六进制转储似乎证实了这一点并给出了一个暗示链接器命令行使用:

link /defaultlib:libcmt /defaultlib:oldnames hello.obj

I had high hopes by this stage but alas it still gives the same unresolved external symbol errors. 我对这个阶段寄予厚望,但是它仍然给出了同样未解决的外部符号错误。

What am I still missing? 我还缺少什么?

事实证明Clang默认生成32位代码,但我使用的是64位MSC,并且随着移动到x64,C符号上的前导_已被删除,因此在clang命令行上指定-m64可以完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM