[英]How do I resolve this error 'cannot find -lc'?
How do I compile this code in CentOS 7?如何在 CentOS 7 中编译此代码? I am reading one book and in the book they use -static while compiling so that's how I did it and I get errors I mentioned below but when I dont use -static I get no errors and it compiles successfully.我正在读一本书,并且在书中他们在编译时使用了 -static ,所以我就是这样做的,我得到了下面提到的错误,但是当我不使用 -static 时,我没有得到任何错误,并且编译成功。
First attempt:第一次尝试:
main()
{
exit(0);
}
I get this error when I try to compile it.当我尝试编译它时出现此错误。
$ gcc -static -o exit exit.c
exit.c: In function _main_:
exit.c:3:9: warning: incompatible implicit declaration of built-in function _exit_ [enabled by default]
exit(0);
^
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
Second attempt:第二次尝试:
Then I google this error and lots of articles told me to include stdlib.h library so I did that as well and I get this error: Code:然后我用谷歌搜索了这个错误,很多文章告诉我要包含 stdlib.h 库,所以我也这样做了,我得到了这个错误:代码:
#include <stdlib.h>
main()
{
exit(0);
}
Now when I compile it, I get following error.现在当我编译它时,我得到以下错误。
$ gcc -static -o exit exit.c
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
linux version: linux版本:
$ uname -a
Linux localhost.localdomain 3.10.0-1127.13.1.el7.centos.plus.i686 #1 SMP Thu Jun 25 16:59:06 UTC 2020 i686 i686 i386 GNU/Linux
As @KamilCuk noted, this requires a different set of libraries for static linking, and on my CentOS 7 machine, this installs the proper libraries:正如@KamilCuk 所指出的,这需要一组不同的库用于 static 链接,在我的 CentOS 7 机器上,这会安装正确的库:
# yum install glibc-static
Then the compile should work as you expect.然后编译应该像你期望的那样工作。
The libraries installed by this package are:此 package 安装的库是:
$ rpm -q -l glibc-static
/usr/lib64/libBrokenLocale.a
/usr/lib64/libanl.a
/usr/lib64/libc.a
/usr/lib64/libc_stubs.a
/usr/lib64/libcrypt.a
/usr/lib64/libdl.a
/usr/lib64/libm.a
/usr/lib64/libnsl.a
/usr/lib64/libpthread.a
/usr/lib64/libresolv.a
/usr/lib64/librt.a
/usr/lib64/libutil.a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.