在Gcc中编译错误

时间:2012-05-27 18:14:34

标签: c linux gcc

我在C.编写了一个程序后用

编译了它
gcc -o pr prc.c 

我得到了下面的东西

/usr/bin/ld:cannot find -lc
collect2: ld returned 1 exit status

2 个答案:

答案 0 :(得分:3)

链接器(ld)找不到标准C库库文件libc.{a|so}。有关此库的提及,请参阅ld man page(以及lc的{​​{1}}命令行选项)。引用:

ld

您应该检查以确保系统中确实缺少这些文件。在我的Ubuntu 10.04 LTS系统上:

ld -o <output> /lib/crt0.o hello.o -lc

This tells ld to produce a file called output as the result of linking
the file "/lib/crt0.o" with "hello.o" and the library "libc.a"

如何安装此缺少的库将根据您的分发情况而有所不同。使用您的包管理来搜索 ~ [88] locate libc.so /lib/libc.so.6 /lib/tls/i686/cmov/libc.so.6 /usr/lib/libc.so ~ [89] locate libc.a /usr/lib/libc.a /usr/lib/xen/libc.a 。否则,您可能需要考虑重新安装libc

答案 1 :(得分:3)

-lc是libc的缩写,它是C运行时库。你的* nix发行版是什么,你需要通过适当的安装程序安装glibc和glibc-common。

man ld,这应该可以提供有关错误消息的信息。这些消息表明链接器正在寻找丢失的库。这里的库名是libc(用lib替换l)。