我刚刚尝试了最新的LLVM and Clang主干版本。他们编译时没有任何开箱即用的警告,但我在链接时遇到问题你好世界!例子。我的代码是
#include <stdio.h>
int main(){
printf("Hello, World!\n");
}
如果我使用编译
clang test.c
我收到以下错误
/usr/bin/ld: crt1.o: No such file: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Using -v表明 GNUld被调用为:
"/usr/bin/ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out crt1.o crti.o crtbegin.o -L -L/../../.. /tmp/cc-0XJTsG.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
但我有 crt1.o 目标文件!
locate crt1.o
Output:
/usr/lib/Mcrt1.o
/usr/lib/Scrt1.o
/usr/lib/crt1.o
/usr/lib/gcrt1.o
这也有效:
clang -c test.c
gcc test.o
而且当然
gcc test.c
我进一步尝试的是:
clang -Xlinker "-L /usr/lib" test.c
/usr/bin/ld: crt1.o: No such file: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang -Xlinker "-L /usr/lib" test.c -v
"/usr/bin/ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out crt1.o crti.o crtbegin.o -L -L/../../.. -L /usr/lib /tmp/cc-YsI9ES.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o
我也尝试复制crt1.o文件到当前目录。这似乎有效。好吧,它没有编译,因为在那之后crti.o失踪。
我的 Linux 发行版是Ubuntu.
好吧,我真的不知道下一步该尝试什么。我不知道如何修复 clang,也不知道如何在ld调用。有任何想法吗?