铛连接问题 [英] clang linker problem
问题描述
我刚刚尝试了最新的LLVM和铿锵主干版本。他们没有一个单一的警告编译开箱即用,但我在链接一个Hello World例子麻烦。我的code是
I just tried out the latest llvm and clang trunk versions. They compiled without a single warning out of the box but I'm having trouble linking a hello world example. My Code is
#include <stdio.h>
int main(){
printf("hello\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)
使用-v显示,GNU LD是用来作为
Using -v shows that the gnu ld is invoked as
"/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对象文件!
But I have the crt1.o object file!
$ locate crt1.o
/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失踪了。
I also tried copying the crt1.o file into the current directory. That seemed to work. Well it didn't compile because after that crti.o was missing.
我的是发行版Ubuntu的。
My distro is Ubuntu.
好吧,我真的不知道下一个尝试的东西。我不看我怎么能解决铛我也不对如何在LD调用注入必要的路径的想法。任何想法?
Well I don't really know what to try next. I don't see how I could fix clang nor do I have an idea on how to inject the necessary path in the ld invocation. Any ideas?
推荐答案
似乎是铛版本,它不能检测到主机的Linux版本和gcc版本。
Seems to be clang version which can't detect host's linux version and gcc version..
这code铛中必须添加到CRT路径*:
LLVM>工具>铛> lib目录>驱动器> Tools.cpp
This code in clang which must add path to the crt*:
llvm›tools›clang›lib›Driver›Tools.cpp
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crt1.o")));
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crti.o")));
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath(C, "crtbegin.o")));
和GetFilePath会尝试搜索请求文件 getFilePaths()当前工具链
列表(文件铛/ lib目录/驱动器/ ToolChains.cpp
)。如果无法找到一个文件时,它会返回名称不变。
and the GetFilePath will try to search asked files in getFilePaths()
list of current ToolChain (file clang/lib/Driver/ToolChains.cpp
). If it can't find a file it will return the Name unchanged.
请,给我你的Ubuntu版本(的uname -a
,猫的/ etc / LSB释放
)铛和LLVM的,确切的发布(SVN版本号),和的gcc -v
输出
Please, give me version of your ubuntu (uname -a
, cat /etc/lsb-release
), exact release (svn revision number) of clang and llvm, and gcc -v
output
这篇关于铛连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!