编译时出错,collect2:找不到ld

时间:2018-10-09 06:11:27

标签: c gcc ld

有人可能遇到了这个问题,我有 collect2:尝试时找不到'ld'错误:

gcc -v -pthread -I /tmp/usr/include -no-use-gold-linker /tmp/teeest.c -o /tmp/teeest > /tmp/ok.log  2>/tmp/error.log

输出:

Using built-in specs.
gcc: unrecognized option '-no-use-gold-linker'
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-pthread' '-I' '/tmp/usr/include' '-no-use-gold-linker' '-o' '/tmp/teeest' '-mtune=generic'
 /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1 -quiet -v -I /tmp/usr/include -iprefix ../lib/gcc/x86_64-redhat-linux/4.4.7/ -D_REENTRANT /tmp/teeest.c -quiet -dumpbase teeest.c -mtune=generic -auxbase teeest -version -o /tmp/ccVr6ozd.s
ignoring nonexistent directory "../lib/gcc/x86_64-redhat-linux/4.4.7/include"
ignoring nonexistent directory "../lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "../lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
ignoring nonexistent directory "../lib/../lib/gcc/x86_64-redhat-linux/4.4.7/include"
ignoring nonexistent directory "../lib/../lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"
ignoring nonexistent directory "../lib/../lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /tmp/usr/include
 /usr/local/include
 /usr/include
End of search list.
GNU C (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-17) (x86_64-redhat-linux)
    compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-17), GMP version 4.3.1, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d2ae160e13b93f509f25a064aa53b455
COLLECT_GCC_OPTIONS='-v' '-pthread' '-I' '/tmp/usr/include' '-no-use-gold-linker' '-o' '/tmp/teeest' '-mtune=generic'
 as -V -Qy -o /tmp/ccCIoBhH.o /tmp/ccVr6ozd.s
GNU assembler version 2.20.51.0.2 (x86_64-redhat-linux) using BFD version version 2.20.51.0.2-5.44.el6 20100205
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:../lib/../lib64/:/lib/../lib64/:/usr/lib/../lib64/:../lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-pthread' '-I' '/tmp/usr/include' '-no-use-gold-linker' '-o' '/tmp/teeest' '-mtune=generic'
 /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /tmp/teeest /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L../lib/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L../lib /tmp/ccCIoBhH.o -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/../lib64/crtn.o
collect2: cannot find 'ld'

检查ld是否存在:

ld: /usr/bin/ld /usr/share/man/man1/ld.1.gz

检查$ PATH

/usr/local/bin:/bin:/usr/bin

我尝试在/ tmp dir中的C上编译hello world应用程序。 CentOS 6,2016,2.6.32-642.1.1.el6.x86_64,x86_64

1 个答案:

答案 0 :(得分:-1)

PATH=$PATH; export PATH; gcc -v -pthread -I /tmp/usr/include /tmp/test.c -o /tmp/test > /tmp/ok.log  2>/tmp/error.log; #eto pizdez