无法使用 clang 编译和链接程序

发布于 2024-12-09 02:41:40 字数 2957 浏览 1 评论 0原文

我最近在 Ubuntu 系统上编译了 Clang 2.9(来自此处)。我在编译和链接一个简单的程序时遇到问题。有谁知道如何解决这个问题?这是我看到的输出:

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 输出

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

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾冷 2024-12-16 02:41:40

听起来像是链接描述文件中的问题。但是上面的 ld 行不包含特定的链接器脚本,因此应该使用默认的链接器脚本(要查看它,只需键入 ld -v )。

-L -L/../../..
这看起来确实有点奇怪。但在你原来的线路上看不到它,所以不确定它来自哪里。也许您的安装已损坏?

执行 gcc -v add.c 并比较调用 /usr/bin/ld 的行。也许将其添加到问题中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文