使用 clang-cl 编译有效,但链接无法找到基本的 libc 符号

Compiling with clang-cl works, but linking fails to find basic libc symbols

对于编译为 LLVM IR 的我的语言 (Runa),我正在尝试启用编译为 Windows。我想启用与 MSVC 编译的东西的链接,所以我想使用 MSVC 目标三元组。我安装了 MSVC Community 2013 并有一个 cmd.exe window,我在其中运行了随附的 vcvars32.bat 脚本,因此已将一堆 MSVC 内容添加到 PATH。但是,在尝试编译时,出现以下链接器错误:

hello-163edf.obj : error LNK2019: unresolved external symbol malloc referenced in function runa.malloc
hello-163edf.obj : error LNK2019: unresolved external symbol free referenced in function runa.free
hello-163edf.obj : error LNK2019: unresolved external symbol memcpy referenced in function runa.memcpy
hello-163edf.obj : error LNK2019: unresolved external symbol write referenced in function runa.unhandled
hello-163edf.obj : error LNK2019: unresolved external symbol exit referenced in function runa.clean
hello-163edf.obj : error LNK2019: unresolved external symbol _Unwind_RaiseException referenced in function runa.raise
hello-163edf.obj : error LNK2019: unresolved external symbol snprintf referenced in function float.__str__
hello-163edf.obj : error LNK2019: unresolved external symbol strlen referenced in function uint.__str__
hello-163edf.obj : error LNK2019: unresolved external symbol __chkstk referenced in function str.__eq__
hello-163edf.obj : error LNK2019: unresolved external symbol strncmp referenced in function str.__eq__
hello-163edf.obj : error LNK2001: unresolved external symbol _fltused

我理解关于 _Unwind_RaiseException 的那个,它可能不符合这个目标,但我不清楚为什么找不到像 malloc() 这样的基本 libc 东西。

其中大部分通过在我的编译器调用末尾添加 /link msvcrt.lib 来解决。

根据您的构建过程和 visual studio 的版本,您可能需要 msvcrt、vcruntime 和 ucrt。请参阅此 post 以获得更多 in-depth 解释:https://devblogs.microsoft.com/cppblog/introducing-the-universal-crt/