gcc连接静态库的时候的出现错误/usr/bin/ld: cannot find -lc

gcc连接静态库的时候的出现错误/usr/bin/ld: cannot find -lc

gcc连接静态库的时候出现错误提示:/usr/bin/ld: cannot find -lc

具体过程:gcc main.c -o test -Ladd -ladd -Lsub -lsub -Iadd -Isub -static ;错误:/usr/bin/ld: cannot find -lc

问题出在静态编译时需要链接静态库,而静态编译时需要将所有的.a库链接到可执行程序中,所以需要libc的静态库文件。

我们可以使用rpm -ql glibc-static命令查看静态库文件是否存在

结果为:package glibc-static is not installed

我们可以下载glibc-static文件,使用 rpm -iv filename.rpm安装即可,或则利用yum install glibc-static安装

安装好了,连接静态库就可以了

推荐阅读