gcc使用buildroot生成的库报错

1 问题描述

在编译curl相关的应用的时候,GCC报错,提示找不到libpthread.so.0

mips-linux-gnu-gcc  curl_ftp.c -L../../../buildroot/output/staging/usr/lib -lpthread -lz -lcurl -lcrypto -lssl -Wall -I/home/hhp/x2000/x2000_v5.0/buildroot/output/staging/usr/include -O2 -o test
/home/hhp/x2000/x2000_v5.0/prebuilts/toolchains/mips-gcc720-glibc226/bin/../lib/gcc/mips-linux-gnu/7.2.0/../../../../mips-linux-gnu/bin/ld: cannot find /lib/libpthread.so.0
/home/hhp/x2000/x2000_v5.0/prebuilts/toolchains/mips-gcc720-glibc226/bin/../lib/gcc/mips-linux-gnu/7.2.0/../../../../mips-linux-gnu/bin/ld: cannot find /usr/lib/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
Makefile:12: recipe for target 'test' failed
make: *** [test] Error 1

2 原因

因为curl_ftp.c应用需要libcurl.so,我的curl是通过buildroot编译出来的,所以通过 -L../../../buildroot/output/staging/usr/lib指定一下libcurl.so所在路径,但是只要指定这个路径就会报错,找不到libpthread.so.0,

进入到../../../buildroot/output/staging/usr/lib目录发现也存在libpthread.so.0,因为-L指定了路径,编译器直接使用了../../../buildroot/output/staging/usr/lib/libpthread.so.0,而这个so是一个错误的动态库,只是一个简单的文本。

hhp@ubuntu:~/x2000/x2000_v5.0/buildroot/output/staging/usr/lib$ ls -l libpthread*
-rw-r--r-- 1 hhp hhp 387982 1月  15 09:17 libpthread.a
-rw-r--r-- 1 hhp hhp   1676 1月  15 09:17 libpthread_nonshared.a
-rw-r--r-- 1 hhp hhp    226 1月  15 09:17 libpthread.so           
hhp@ubuntu:~/x2000/x2000_v5.0/buildroot/output/staging/usr/lib$ cat libpthread.so 
/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-tradlittlemips)
GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )
hhp@ubuntu:~/x2000/x2000_v5.0/buildroot/output/staging/usr/lib$ 
hhp@ubuntu:~/x2000/x2000_v5.0/buildroot/output/staging/usr/lib$ 
hhp@ubuntu:~/x2000/x2000_v5.0/buildroot/output/staging/usr/lib$ 
hhp@ubuntu:~/x2000/x2000_v5.0/buildroot/output/staging/usr/lib$ 

3 解决办法

使用-L../../../buildroot/output/target/usr/lib下面的库进行编译,这个路径下的库也是buildroot生成的,区别是都是动态库并且没有其他乱七八糟的文件

mips-linux-gnu-gcc  curl_ftp.c -L../../../buildroot/output/target/usr/lib -lpthread -lz -lcurl -lcrypto -lssl -Wall -I/home/hhp/x2000/x2000_v5.0/buildroot/output/staging/usr/include -O2 -o test

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值