gcc static静态编译选项提示错误:/usr/lib/ld:cannot find -lc

本文介绍了在使用GCC进行静态库编译时遇到的常见错误“/usr/lib/ld:cannotfind-lc”等问题的原因及解决办法,并对比了静态库与动态库编译的区别。

在学习gcc静态库动态库编译的时候选用静态库编译时出错显示:/usr/lib/ld:cannot find -lc

百度:/usr/lib/ld:cannot find -lc多处给的解决方案为:

然而并不能解决问题,最终定位发现是静态编译的问题。而且不止会出现这种情况:

/usr/lib/ld:cannot find -lc

/usr/lib/ld:cannot find -lgcc_s

/usr/lib/ld:cannot find -lm

等的错误,主要原因在静态编译时需要链接静调库。如上命令:

[xiaohexiansheng@centos6 app]$ gcc -static -I./libs main.c -o app -L./libs -lcrypto -lfunc

如果在编译时去掉-static选项选用动态库编译则不会出现此种情况

[xiaohexiansheng@centos6 app]$ gcc -I./libs main.c -o app -L./libs -lcrypto -lfunc
[xiaohexiansheng@centos6 app]$ ls
app  libs  main.c

非静态编译时ldd filename,显示如下,这是可执行程序所需的动态库,运行可执行程序时需要的动态库。

[xiaohexiansheng@centos6 app]$ ldd app
        linux-gate.so.1 =>  (0x004ad000)
        libcrypto.so => /usr/lib/libcrypto.so (0x03ad9000)
        libfunc.so => not found
        libc.so.6 => /lib/libc.so.6 (0x0052a000)
        libdl.so.2 => /lib/libdl.so.2 (0x0070c000)
        libz.so.1 => /lib/libz.so.1 (0x00713000)
        /lib/ld-linux.so.2 (0x00508000)

静态编译时需要将所有的.a库链接到可执行文件中,所以需要libc静态库文件,在系统找查找glibc-static提示没有库文件。

#yum install glibc-static安装静态库。

转载于:https://www.cnblogs.com/xiaohexiansheng/p/5500870.html

/opt/android-ndk-r18b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --sysroot=/opt/android-ndk-r18b/sysroot -I/include -fPIC -c -o /tmp/ffconf.3S9556Zm/test.o /tmp/ffconf.3S9556Zm/test.c /opt/android-ndk-r18b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -L/lib -L/opt/android-ndk-r18b/sysroot/usr/lib -lmpp -lunwind --sysroot=/opt/android-ndk-r18b/sysroot -o /tmp/ffconf.3S9556Zm/test /tmp/ffconf.3S9556Zm/test.o /..//bin/ld: cannot find crt1.o: No such file or directory /..//bin/ld: cannot find crti.o: No such file or directory /..//bin/ld: cannot find crtbegin.o: No such file or directory /..//bin/ld: cannot find -lmpp /..//bin/ld: cannot find -lunwind /..//bin/ld: cannot find -lgcc /..//bin/ld: cannot find -lgcc_s /..//bin/ld: cannot find -lc /..//bin/ld: cannot find -lgcc /..//bin/ld: cannot find -lgcc_s /..//bin/ld: cannot find crtend.o: No such file or directory /..//bin/ld: cannot find crtn.o: No such file or directory clang: error: linker command failed with exit code 1 (use -v to see invocation) C compiler test failed.还是出现了问题,这是命令:./configure --target-os=android --arch=aarch64 --enable-cross-compile --cross-prefix=$TOOLCHAIN/bin/$TARGET$API- --sysroot=/opt/android-ndk-r18b/sysroot --cc=$TOOLCHAIN/bin/clang --cxx=$TOOLCHAIN/bin/clang++ --enable-rkmpp --enable-libdrm --extra-cflags="-I$MPP_ROOT/include -fPIC" --enable-shared --enable-version3 --disable-static --disable-doc --extra-ldflags="-L$MPP_ROOT/lib -L/opt/android-ndk-r18b/sysroot/usr/lib -lmpp -lunwind"
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值