ld: cannot find -lxxx

LD 找不到 -l问题的统一解决

/usr/bin/ld: cannot find -l
collect2: error: ld returned 1 exit status

1
ld -l<xxx> --verbose

/usr/bin/ld: cannot find -lhdb

1
2
3
4
5
6
7
8
9
ld -lhdb --verbose
...
attempt to open /usr/lib64/libhdb.so failed
attempt to open /usr/lib64/libhdb.a failed
attempt to open /usr/local/lib64/libhdb.so failed
attempt to open /usr/local/lib64/libhdb.a failed
attempt to open /lib64/libhdb.so failed
attempt to open /lib64/libhdb.a failed
...

可以看到ld在尝试从哪些地方寻找所需的文件

然后就方面通过文件名判断该安装什么包或者做软连接

1
2
3
4
5
6
locate libhdb
/usr/lib64/heimdal/libhdb.a
/usr/lib64/heimdal/libhdb.so
/usr/lib64/heimdal/libhdb.so.9
/usr/lib64/heimdal/libhdb.so.9.2.0
ln -s /usr/lib64/heimdal/libhdb.so /usr/lib64/libhdb.so