各种计算软件在编译的时候,不时会出现ld的报错,提示没有找到-lxxxx的
例如以下错误

/usr/bin/ld: cannot find -lckmain
/usr/bin/ld: cannot find -lck
/usr/bin/ld: cannot find -lmemory-default
/usr/bin/ld: cannot find -lthreads-default
/usr/bin/ld: cannot find -lconv-machine
/usr/bin/ld: cannot find -lconv-core
/usr/bin/ld: cannot find -ltmgr
/usr/bin/ld: cannot find -lconv-util
/usr/bin/ld: cannot find -lconv-partition
collect2: error: ld returned 1 exit status

可以看出是好些链接库没有找到

此时,通用的解决方案的话,就是

ld -lckmain --verbose

检查输出,发现如下报错
==================================================

attempt to open //usr/local/lib/x86_64-linux-gnu/libckmain.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libckmain.a failed
attempt to open //lib/x86_64-linux-gnu/libckmain.so failed
attempt to open //lib/x86_64-linux-gnu/libckmain.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libckmain.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libckmain.a failed
attempt to open //usr/lib/x86_64-linux-gnu64/libckmain.so failed
attempt to open //usr/lib/x86_64-linux-gnu64/libckmain.a failed
attempt to open //usr/local/lib64/libckmain.so failed
attempt to open //usr/local/lib64/libckmain.a failed
attempt to open //lib64/libckmain.so failed
attempt to open //lib64/libckmain.a failed
attempt to open //usr/lib64/libckmain.so failed
attempt to open //usr/lib64/libckmain.a failed
attempt to open //usr/local/lib/libckmain.so failed
attempt to open //usr/local/lib/libckmain.a failed
attempt to open //lib/libckmain.so failed
attempt to open //lib/libckmain.a failed
attempt to open //usr/lib/libckmain.so failed
attempt to open //usr/lib/libckmain.a failed
attempt to open //usr/x86_64-linux-gnu/lib64/libckmain.so failed
attempt to open //usr/x86_64-linux-gnu/lib64/libckmain.a failed
attempt to open //usr/x86_64-linux-gnu/lib/libckmain.so failed
attempt to open //usr/x86_64-linux-gnu/lib/libckmain.a failed
ld: cannot find -lckmain

看出来,原因其实就是系统搜索路径里面找不到.so或者.a的文件
解决方案的话,其实就是指定链接位置,就可以了。

比如在编译的时候加 -L 参数,指定一下链接文件的位置;比如使用c编译器的时候,额外设定一下CFLAGS

export CFLAGS="-L/home/yingjin/Softwares/charm-6.9.0/lib“

CMake的话,使用以下

 CMAKE_CXX_FLAGS                  -std=c++11  -L/home/yingjin/Softwares/charm-6.9.0/lib

就可以了
(注意ccmake可能需要t显示详细菜单后,才能见此选项)

  • tec_ld.txt
  • Last modified: 2019/09/24 00:23
  • (external edit)