不能编译和链接铿锵方案 [英] Can't compile and link programs with clang

查看:134
本文介绍了不能编译和链接铿锵方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近编译锵2.9(从这里 )的Ubuntu系统上。我无法编译和链接一个简单的程序。有谁知道如何解决这一问题?这是我看到的输出:

  A @ Ubuntu的:〜/桌面$铛add.c
在/ usr /斌/劳工处:1:语法错误:意外字(预期))
铿锵:错误:连接命令,退出code 2(使用-v看看调用)失败

的uname -a输出

  Linux操作系统Ubuntu 2.6.38-8泛型#42 Ubuntu的SMP周一年04月11 UTC 3时31分50秒2011的i686 i686的的i386 GNU / Linux的

GCC -v输出:

 使用内置的规格。COLLECT_GCC = GCCCOLLECT_LTO_WRAPPER = / usr / lib目录/ I386-Linux的GNU / GCC / i686的-Linux的GNU / 4.5.2 / LTO-包装目标:i686的Linux的GNU的../src/configure -v --with-pkgversion ='的Ubuntu / Linaro的4.5.2-8ubuntu4 --with-bugurl =文件:///usr/share/doc/gcc-4.5/README.Bugs与配置--enable-语言= C,C ++,FORTRAN,objc,OBJ-C ++  -  preFIX =的/ usr --program后缀= -4.5 --enable-共享--enable-multiarch --with-multiarch-默认值= I386-Linux的GNU --enable-连接建造-ID --with-系统的zlib --libexecdir = / usr / lib目录/ I386-Linux的GNU --without-包括-gettext的--enable-线程= POSIX --with-GXX-包括-DIR = / usr / include目录/ C ++ / 4.5 = --libdir / usr / lib目录/ I386-Linux的GNU --enable-NLS --with-SYSROOT = / --enable-clocale = GNU --enable-libstdcxx调试--enable-libstdcxx时间= YES --enable-插件--enable-金--enable-LD =默认--with-插件-LD = ld.gold --enable- objc-GC --enable-目标=所有--disable-werror --with拱-32 = i686的--with调整=通用--enable-检查=发行--build = i686的Linux的GNU的--host = i686的Linux的GNU的--target = i686的Linux的GNU的线程模型:POSIXgcc版本4.5.2(Ubuntu的/ Linaro的4.5.2-8ubuntu4)

铛冗长的输出中

 铛版本2.9(标签/ RELEASE_29 /决赛)目标:I386-PC-Linux的GNU线程模型:POSIX在/ usr / local / bin目录/铛-cc1  - 三I386-PC-Linux的GNU -emit-OBJ -mrelax,全部免费-disable--disable-LLVM  - 验证 - 主文件名add.c -mrelocation -model静态-mdisable-FP-琳-masm-详细-mconstructor-别名-target-CPU的Pentium4 -target链接器版本2.21.0.20110327 -momit叶帧指针-v -resource-DIR在/ usr /本地/斌/../的lib /铛/ 2.9 -ferror限制19 -fmessage长度138 -fgnu运行时-fdiagnostics出现选项-fcolor诊断-o /tmp/cc-JJruTv.o -xc add.c铛-cc1 2.9版本基于托管在i386-PC-Linux的GNU LLVM 2.9的#include...的搜索从这里开始:#包括LT&; ...>搜索从这里开始: 在/ usr /本地/包括 /usr/local/bin/../lib/clang/2.9/include / usr / include目录搜索列表结束。 在/ usr /斌/ LD--eh帧HDR -m elf_i386 -dynamic-连接/lib/ld-linux.so.2 -o a.out的crt1.o crti.o crtbegin.o -L -L /../../ .. /tmp/cc-JJruTv.o -lgcc --as急需-lgcc_s --no-按需-lc -lgcc --as急需-lgcc_s --no-AS-所需crtend.o crtn.o在/ usr /斌/劳工处:1:语法错误:意外字(预期))铿锵:错误:连接命令,退出code 2(使用-v看看调用)失败


听起来像是在你的链接脚本的一个问题。但是LD线以上不包含的链接描述这样一个默认应使用(看到它只需键入 LD -v )。

-L -L /../../..
这看起来的确有点不可思议。不要看到它在你的原线,但这样不知道它是从哪里来的。也许你的安装被打破?

做一个 GCC -v add.c 和比较调用行的/ usr / bin中/ LD 。也许它添加到这个问题。

I recently compiled Clang 2.9 (from here) on an Ubuntu system. I'm having trouble compiling and linking a simple program. Does anyone know how to fix this? Here's the output I see:

a@ubuntu:~/Desktop$ clang add.c
/usr/bin/ld: 1: Syntax error: word unexpected (expecting ")")
clang: error: linker command failed with exit code 2 (use -v to see invocation)

uname -a output

Linux ubuntu 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux 

gcc -v output:

Using built-in specs.

COLLECT_GCC=gcc

COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper

Target: i686-linux-gnu

Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4 --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu

Thread model: posix

gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)

clang verbose ouput

clang version 2.9 (tags/RELEASE_29/final)

Target: i386-pc-linux-gnu

Thread model: posix

"/usr/local/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name add.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.21.0.20110327 -momit-leaf-frame-pointer -v -resource-dir /usr/local/bin/../lib/clang/2.9 -ferror-limit 19 -fmessage-length 138 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-JJruTv.o -x c add.c

clang -cc1 version 2.9 based upon llvm 2.9 hosted on i386-pc-linux-gnu

#include "..." search starts here:

#include <...> search starts here:

 /usr/local/include

 /usr/local/bin/../lib/clang/2.9/include

 /usr/include

End of search list.

 "/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-JJruTv.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o

/usr/bin/ld: 1: Syntax error: word unexpected (expecting ")")

clang: error: linker command failed with exit code 2 (use -v to see invocation)

解决方案

Sounds like a problem in your linker script. But the ld line above does not contain a specific linker script so the default one should be used (to see it simply type ld -v).

-L -L/../../.. that does look a bit weird. Don't see it on your original line though so not sure where it came from. Perhaps your installation is broken?

Do a gcc -v add.c and compare the lines invoking /usr/bin/ld. Perhaps add it to the question.

这篇关于不能编译和链接铿锵方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆