我正在尝试使用clang交叉编译到Linux上的Windows。我认为我需要从其他地方获取标准库的东西,所以我在Windows上编译时使用了-v来查看Windows clang使用的是什么,然后将这些文件复制到Linux上。现在,我正在使用如下所示的脚本进行编译:
#!/bin/bash
clang++ -fuse-ld=lld -target x86_64-pc-windows-msvc \
-I /home/.../include/clang \
-I /home/.../include/msvc \
-I /home/.../include/atlmfc \
-I /home/.../include/ucrt \
-I /home/.../include/shared \
-I /home/.../include/um \
-I /home/.../include/winrt \
-L /home/.../lib/msvc \
-L /home/.../lib/atlmfc \
-L /home/.../lib/ucrt \
-L /home/.../lib/um \
-L /home/.../lib/clang \
$@这是我正在尝试编译的测试程序:
int main(int argc, char* argv[])
{
return argc;
}一开始,我遇到了一个问题,一些库(kernel32.Lib和Uuid.Lib)找不到,但它似乎是由于区分大小写而引起的,所以使用两个全小写的符号链接很容易解决这个问题。
但是现在lld-link抱怨"__memset_nt_iters“没有定义,我不知道这是怎么回事。查看详细输出:
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: /usr/bin
"/usr/lib/llvm-10/bin/clang" -cc1 -triple x86_64-pc-windows-msvc19.11.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ret.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -v -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -I /home/.../include/clang -I /home/.../include/msvc -I /home/.../include/atlmfc -I /home/.../include/ucrt -I /home/.../include/shared -I /home/.../include/um -I /home/.../include/winrt -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -fdeprecated-macro -fdebug-compilation-dir /home/... -ferror-limit 19 -fmessage-length 0 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o /tmp/ret-004e99.o -x c++ ret.cpp
clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target x86_64-pc-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
/home/.../include/clang
/home/.../include/msvc
/home/.../include/atlmfc
/home/.../include/ucrt
/home/.../include/shared
/home/.../include/um
/home/.../include/winrt
/usr/lib/llvm-10/lib/clang/10.0.0/include
End of search list.
"/usr/lib/llvm-10/bin/lld-link" -out:ret.exe -libpath:lib/amd64 -libpath:atlmfc/lib/amd64 -libpath:/home/.../lib/msvc -libpath:/home/.../lib/atlmfc -libpath:/home/.../lib/ucrt -libpath:/home/.../lib/um -libpath:/home/.../lib/clang -nologo /tmp/ret-004e99.o libcmt.lib
lld-link: error: undefined symbol: __memset_nt_iters
>>> referenced by D:\a01\_work\9\s\src\vctools\crt\vcruntime\src\string\amd64\memset.asm:134
>>> libvcruntime.lib(memset.obj):(XmmSetLarge)
clang: error: linker command failed with exit code 1 (use -v to see invocation)发布于 2021-06-15 18:39:31
我现在已经设法让它编译了。我所做的是添加参数-Xlinker /force,这使链接器忽略了存在未定义符号的事实,并继续执行。生成的可执行文件(通过编译测试程序)似乎运行得很好,至少在Wine中是这样。
有趣的是,当我编译一个更大的项目时,关于"__memset_nt_iters“的错误(现在是警告)消失了。在这种情况下,我无法确定是什么解决了这个问题。
https://stackoverflow.com/questions/67970431
复制相似问题