编译软件时,经常遇到/usr/bin/ld:cannot find -lxxx报错,其报错原因就是gcc在搜索路径下找不到xxx库文件。

1. 问题分析

楼主在编译软件时,出现了如下报错:
```bash
/usr/bin/ld: cannot find -lf77blas
/usr/bin/ld: cannot find -latlas
collect2: error: ld returned 1 exit status
```
报错信息的意思是,gcc在搜索路径中找不到 libf77blas.so、libatlas.so库文件。

可以使用 gcc -lxxx --verbose 命令去验证,跟上面的报错是一样的。

2. 解决方法:

只需要安装xxx软件,找到libxxx.so文件,再把文件添加到gcc搜搜目录下即可。

3. 样例:

/usr/bin/ld: cannot find -latlas报错信息举例

  • 首先安装atlas软件,直接运行yum install atlas
  • 然后找到atlas安装目录,运行find / -name atlas,确定libsatlas.so.3.10文件在/usr/lib64/atlas
    目录下
# find / -name atlas
/usr/share/doc/atlas
/usr/include/atlas
/usr/lib64/atlas
/usr/lib/debug/usr/lib64/atlas
  • 由于gcc的搜索目录包含/usr/lib64/,直接拷贝即可
    cp /usr/lib64/atlas/libsatlas.so.3.10 /usr/lib64/
  • 目标文件是libatlas.so,只需要制作软链接即可。
    ln -s libsatlas.so.3.10 libsatlas.so
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐