ubuntu下当执行 llvm-gcc hello.c -o hello 命令,若出现:
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: ld returned 1 exit status
解决方法如下:
1.在系统中查找crti.o
sudo find /usr/ -name crti*
将得到结果:
(32位)/usr/lib/i386-linux-gnu/crti.o
(64位)/usr/lib/x86_64-linux-gnu/crti.o
2.将该路径添加到LIBRARY_PATH
方法一:(仅当前shell生效,关闭shell将失效)
(32位)
LIBRARY_PATH=/usr/lib/i386-linux-gnu:$LIBRARY_PATH
export LIBRARY_PATH
(64位)
LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
export LIBRARY_PATH
方法二:(永久生效)
(32位)
$ echo "export LIBRARY_PATH=/usr/lib/i386-linux-gnu" >> ~/.bashrc
$ source ~/.bashrc
(64位)
$ echo "export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu" >> ~/.bashrc
$ source ~/.bashrc
3.再次执行,顺利编译
4.查看LIBRARY_PATH
echo $LIBRARY_PATH