2011-10-10 47 views
1

我最近編譯的Clang 2.9(從here)在Ubuntu系統上。我無法編譯和鏈接一個簡單的程序。有誰知道如何解決這一問題?這裏的輸出我看到:無法編譯和鏈接程序與鐺

[email protected]:~/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輸出

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輸出:

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 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) 
+2

add.c中有什麼? – wormsparty

回答

2

聽起來像是鏈接描述文件中的問題。但是上面的ld行不包含特定的鏈接描述文件,因此應該使用默認鏈接腳本(只需鍵入ld -v即可)。

-L -L/../../.. 確實看起來有點奇怪。儘管不確定它來自哪裏,但不要在原始行上看到它。也許你的安裝被破壞了?

做一個gcc -v add.c和比較線條調用/usr/bin/ld。也許增加它的問題。

+0

感謝您的幫助。原來'/ usr/bin/ld'被另一個文件覆蓋了。我不確定發生了什麼,但通過調查'gcc -v add.c'的輸出,我能夠做出這個決定。我最終取代了/ usr/bin/ld並讓所有的東西都起作用。 – Jason