马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 baofu007 于 2021-3-3 14:41 编辑
源文件中#include <math.h>,然后调用了pow或者其他math函数,编译时加了-lm还是报错,这可能是因为libm和libc两个库的版本不一致。
报错信息如下:
(base) root@ubuntu:/home/yongjie/learning/c/s1e15# gcc exer2.c -lm -o exer2
/lib/x86_64-linux-gnu/libm.so.6: undefined reference to `__strtof128_nan@GLIBC_PRIVATE'
collect2: error: ld returned 1 exit status
比如上面这个报错是/lib/x86_64-linux-gnu/libm.so.6库报的错,可以查看这个库的版本
(base) root@ubuntu:/home/yongjie/learning/c/s1e15# ll /lib/x86_64-linux-gnu/libm.so.6
lrwxrwxrwx 1 root root 12 Dec 30 03:28 /lib/x86_64-linux-gnu/libm.so.6 -> libm-2.27.so
再查看libc库的版本(base) root@ubuntu:/home/yongjie/learning/c/s1e15# ll /lib/x86_64-linux-gnu/libc*
-rwxr-xr-x 1 root root 1868984 Jun 5 2020 /lib/x86_64-linux-gnu/libc-2.23.so
lrwxrwxrwx 1 root root 14 May 21 2020 /lib/x86_64-linux-gnu/libcap.so.2 -> libcap.so.2.24
-rw-r--r-- 1 root root 23128 Oct 23 2015 /lib/x86_64-linux-gnu/libcap.so.2.24
-rw-r--r-- 1 root root 190856 Jun 5 2020 /lib/x86_64-linux-gnu/libcidn-2.23.so
lrwxrwxrwx 1 root root 15 Jun 5 2020 /lib/x86_64-linux-gnu/libcidn.so.1 -> libcidn-2.23.so
lrwxrwxrwx 1 root root 17 Jan 22 2020 /lib/x86_64-linux-gnu/libcom_err.so.2 -> libcom_err.so.2.1
-rw-r--r-- 1 root root 14648 Jan 22 2020 /lib/x86_64-linux-gnu/libcom_err.so.2.1
-rw-r--r-- 1 root root 39224 Jun 5 2020 /lib/x86_64-linux-gnu/libcrypt-2.23.so
-rw-r--r-- 1 root root 2365984 Sep 15 15:30 /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
lrwxrwxrwx 1 root root 22 Sep 6 2017 /lib/x86_64-linux-gnu/libcryptsetup.so.4 -> libcryptsetup.so.4.6.0
-rw-r--r-- 1 root root 158920 Sep 6 2017 /lib/x86_64-linux-gnu/libcryptsetup.so.4.6.0
lrwxrwxrwx 1 root root 16 Jun 5 2020 /lib/x86_64-linux-gnu/libcrypt.so.1 -> libcrypt-2.23.so
lrwxrwxrwx 1 root root 12 Jun 5 2020 /lib/x86_64-linux-gnu/libc.so.6 -> libc-2.23.so
发现libm.so.6连接的libm是2.27版本,libc.so.6连接的libc是2.23版本,版本不一致,可以将libm改为引用2.23版本
1、可以看到有一个libm-2.23.so库存在(base) root@ubuntu:/home/yongjie/learning/c/s1e15# ll /lib/x86_64-linux-gnu/libm*
-rw-r--r-- 1 root root 1088952 Jun 5 2020 /lib/x86_64-linux-gnu/libm-2.23.so
-rw-r--r-- 1 root root 1700792 Oct 26 09:25 /lib/x86_64-linux-gnu/libm-2.27.so
-rw-r--r-- 1 root root 18776 Jun 5 2020 /lib/x86_64-linux-gnu/libmemusage.so
lrwxrwxrwx 1 root root 15 May 21 2020 /lib/x86_64-linux-gnu/libmnl.so.0 -> libmnl.so.0.1.0
-rw-r--r-- 1 root root 22520 Aug 28 2014 /lib/x86_64-linux-gnu/libmnl.so.0.1.0
lrwxrwxrwx 1 root root 17 Jan 27 2020 /lib/x86_64-linux-gnu/libmount.so.1 -> libmount.so.1.1.0
-rw-r--r-- 1 root root 286824 Jan 27 2020 /lib/x86_64-linux-gnu/libmount.so.1.1.0
lrwxrwxrwx 1 root root 12 Dec 30 03:28 /lib/x86_64-linux-gnu/libm.so.6 -> libm-2.27.so
-rw-r--r-- 1 root root 166368 Jun 5 2020 /lib/x86_64-linux-gnu/libmvec-2.23.so
lrwxrwxrwx 1 root root 15 Jun 5 2020 /lib/x86_64-linux-gnu/libmvec.so.1 -> libmvec-2.23.so
2、只需要把libm.so.6连接到libm-2.23.so就可以(base) root@ubuntu:/home/yongjie/learning/c/s1e15# cd /lib/x86_64-linux-gnu
(base) root@ubuntu:/lib/x86_64-linux-gnu# rm -rf libm.so.6
(base) root@ubuntu:/lib/x86_64-linux-gnu# ln -s libm-2.23.so libm.so.6
3、查看一下是否连接成功,如下连接成功libm.so.6 -> libm-2.23.so(base) root@ubuntu:/lib/x86_64-linux-gnu# ll /lib/x86_64-linux-gnu/libm*
-rw-r--r-- 1 root root 1088952 Jun 5 2020 /lib/x86_64-linux-gnu/libm-2.23.so
-rw-r--r-- 1 root root 1700792 Oct 26 09:25 /lib/x86_64-linux-gnu/libm-2.27.so
-rw-r--r-- 1 root root 18776 Jun 5 2020 /lib/x86_64-linux-gnu/libmemusage.so
lrwxrwxrwx 1 root root 15 May 21 2020 /lib/x86_64-linux-gnu/libmnl.so.0 -> libmnl.so.0.1.0
-rw-r--r-- 1 root root 22520 Aug 28 2014 /lib/x86_64-linux-gnu/libmnl.so.0.1.0
lrwxrwxrwx 1 root root 17 Jan 27 2020 /lib/x86_64-linux-gnu/libmount.so.1 -> libmount.so.1.1.0
-rw-r--r-- 1 root root 286824 Jan 27 2020 /lib/x86_64-linux-gnu/libmount.so.1.1.0
lrwxrwxrwx 1 root root 12 Mar 3 01:22 /lib/x86_64-linux-gnu/libm.so.6 -> libm-2.23.so
-rw-r--r-- 1 root root 166368 Jun 5 2020 /lib/x86_64-linux-gnu/libmvec-2.23.so
lrwxrwxrwx 1 root root 15 Jun 5 2020 /lib/x86_64-linux-gnu/libmvec.so.1 -> libmvec-2.23.so
4、问题解决(base) root@ubuntu:/home/yongjie/learning/c/s1e15# gcc exer2.c -lm -o exer2
(base) root@ubuntu:/home/yongjie/learning/c/s1e15# ./exer2
Number: 1229
|