本文翻译自:usr/bin/ld: cannot find -l

I'm trying to compile my program and it returns this error : 我正在尝试编译我的程序,它返回此错误:

usr/bin/ld: cannot find -l<nameOfTheLibrary>

in my makefile I use the command g++ and link to my library which is a symbolic link to my library located on an other directory. 在我的makefile文件中,我使用命令g++并链接到我的库,这是到另一个目录中我的库的符号链接。

Is there an option to add to make it work please? 是否可以添加选项以使其正常工作?


#1楼

参考:https://stackoom.com/question/1872t/usr-bin-ld-找不到-l-nameOfTheLibrary


#2楼

When you compile your program you must supply the path to the library; 编译程序时,必须提供库的路径。 in g++ use the -L option: 在g ++中,使用-L选项:

g++ myprogram.cc -o myprogram -lmylib -L/path/foo/bar

#3楼

If your library name is say libxyz.so and it is located on path say: 如果您的库名称为libxyz.so且位于路径中,请说:

/home/user/myDir

then to link it to your program: 然后将其链接到您的程序:

g++ -L/home/user/myDir -lxyz myprog.cpp -o myprog

#4楼

To figure out what the linker is looking for, run it in verbose mode. 要弄清楚链接程序在寻找什么,请在详细模式下运行它。

For example, I encountered this issue while trying to compile MySQL with ZLIB support. 例如,当我尝试使用ZLIB支持编译MySQL时遇到了这个问题。 I was receiving an error like this during compilation: 我在编译期间收到这样的错误:

/usr/bin/ld: cannot find -lzlib

I did some Googl'ing and kept coming across different issues of the same kind where people would say to make sure the .so file actually exists and if it doesn't, then create a symlink to the versioned file, for example, zlib.so.1.2.8. 我做了一些Googl'ing操作,并不断遇到同类问题,人们会说要确保.so文件确实存在,如果不存在,则创建指向版本文件的符号链接,例如zlib。所以1.2.8。 But, when I checked, zlib.so DID exist. 但是,当我检查时,zlib.so DID存在。 So, I thought, surely that couldn't be the problem. 所以,我想,那肯定不是问题。

I came across another post on the Internets that suggested to run make with LD_DEBUG=all: 我在互联网上遇到了另一条建议使用LD_DEBUG = all运行make的帖子:

LD_DEBUG=all make

Although I got a TON of debugging output, it wasn't actually helpful. 尽管我得到了大量调试信息,但实际上并没有帮助。 It added more confusion than anything else. 它比其他任何事情都增加了混乱。 So, I was about to give up. 所以,我正要放弃。

Then, I had an epiphany. 然后,我顿悟了。 I thought to actually check the help text for the ld command: 我认为实际上要检查ld命令的帮助文本:

ld --help

From that, I figured out how to run ld in verbose mode (imagine that): 由此,我想出了如何在详细模式下运行ld(想象一下):

ld -lzlib --verbose

This is the output I got: 这是我得到的输出:

==================================================
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libzlib.a failed
attempt to open /usr/local/lib64/libzlib.so failed
attempt to open /usr/local/lib64/libzlib.a failed
attempt to open /lib64/libzlib.so failed
attempt to open /lib64/libzlib.a failed
attempt to open /usr/lib64/libzlib.so failed
attempt to open /usr/lib64/libzlib.a failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.so failed
attempt to open /usr/x86_64-linux-gnu/lib/libzlib.a failed
attempt to open /usr/local/lib/libzlib.so failed
attempt to open /usr/local/lib/libzlib.a failed
attempt to open /lib/libzlib.so failed
attempt to open /lib/libzlib.a failed
attempt to open /usr/lib/libzlib.so failed
attempt to open /usr/lib/libzlib.a failed
/usr/bin/ld.bfd.real: cannot find -lzlib

Ding, ding, ding... 叮,叮...

So, to finally fix it so I could compile MySQL with my own version of ZLIB (rather than the bundled version): 因此,最后修复它,以便可以使用自己的ZLIB版本(而不是捆绑版本)来编译MySQL:

sudo ln -s /usr/lib/libz.so.1.2.8 /usr/lib/libzlib.so

Voila! 瞧!


#5楼

During compilation with g++ via make define LIBRARY_PATH if it may not be appropriate to change the Makefile with the -L option. 在使用g++进行编译的过程中,如果可能不适合使用-L选项更改Makefile,则通过make定义LIBRARY_PATH I had put my extra library in /opt/lib so I did: 我将额外的库放在/opt/lib所以我这样做了:

$ export LIBRARY_PATH=/opt/lib/

and then ran make for successful compilation and linking. 然后运行make进行成功的编译和链接。

To run the program with a shared library define: 要使用共享库运行程序,请定义:

$ export LD_LIBRARY_PATH=/opt/lib/

before executing the program. 在执行程序之前。


#6楼

Compile Time 编译时间

When g++ says cannot find -l<nameOfTheLibrary> , it means that g++ looked for the file lib{nameOfTheLibrary}.so , but it couldn't find it in the shared library search path, which by default points to /usr/lib and /usr/local/lib and somewhere else maybe. 当g ++说cannot find -l<nameOfTheLibrary> ,表示g ++在lib{nameOfTheLibrary}.so文件中寻找,但在共享库搜索路径中找不到它,默认情况下它指向/usr/lib/usr/local/lib和其他地方。

To resolve this problem, you should either provide the library file ( lib{nameOfTheLibrary}.so ) in those search paths or use -L command option. 要解决此问题,您应该在这些搜索路径中提供库文件( lib{nameOfTheLibrary}.so ),或使用-L命令选项。 -L{path} tells the g++ (actually ld ) to find library files in path {path} in addition to default paths. -L{path}告诉g ++(实际上是ld )在默认路径之外查找路径{path}中的库文件。

Example: Assuming you have a library at /home/taylor/libswift.so , and you want to link your app to this library. 示例:假设您在/home/taylor/libswift.so有一个库,并且想要将应用程序链接到该库。 In this case you should supply the g++ with the following options: 在这种情况下,您应该为g ++提供以下选项:

g++ main.cpp -o main -L/home/taylor -lswift
  • Note 1 : -l option gets the library name without lib and .so at its beginning and end. 注1-l选项在开始和结束时获取不带 lib.so的库名。

  • Note 2 : In some cases, the library file name is followed by its version, for instance libswift.so.1.2 . 注2 :在某些情况下,库文件名后跟版本,例如libswift.so.1.2 In these cases, g++ also cannot find the library file. 在这些情况下,g ++也找不到该库文件。 A simple workaround to fix this is creating a symbolic link to libswift.so.1.2 called libswift.so . 解决此问题的简单方法是创建指向libswift.so.1.2的符号链接,称为libswift.so


Runtime 运行

When you link your app to a shared library, it's required that library stays available whenever you run the app. 当您将应用程序链接到共享库时,需要在运行该应用程序时该库保持可用。 In runtime your app (actually dynamic linker) looks for its libraries in LD_LIBRARY_PATH . 在运行时,您的应用程序(实际上是动态链接器)在LD_LIBRARY_PATH查找其库。 It's an environment variable which stores a list of paths. 这是一个环境变量,用于存储路径列表。

Example: In case of our libswift.so example, dynamic linker cannot find libswift.so in LD_LIBRARY_PATH (which points to default search paths). 示例:在我们的libswift.so示例中,动态链接程序无法在LD_LIBRARY_PATH (指向默认搜索路径)中找到libswift.so To fix the problem you should append that variable with the path libswift.so is in. 要解决此问题,您应该将该变量附加libswift.so所在的路径。

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/taylor

usr / bin / ld:找不到-l <nameOfTheLibrary>相关推荐

  1. 解决Linux系统下,“/usr/bin/ld: 找不到 -lXXX”问题

    参考链接:(5条消息) 解决Make时,"/usr/bin/ld: 找不到 -lXXX"问题的四种方法_回音谷的博客-CSDN博客 本文以Xxf86vm库作为例子,遇到不同的库直接 ...

  2. C 编程异常 — /usr/bin/ld: 找不到 -lm

    问题:在编程程序的时候报错. /usr/bin/ld: 找不到 -lm /usr/bin/ld: 找不到 -lc 原因:缺少库文件. 解决: yum install -y libstdc++-stat ...

  3. /usr/bin/ld: 找不到 -lopencv_dep_cudart

    make出现/usr/bin/ld: 找不到 -lopencv_dep_cudart错误时候 我们在cmake时候加上参数 cmake -D CUDA_USE_STATIC_CUDA_RUNTIME= ...

  4. /usr/bin/ld: 找不到 -lmsc----解决方案

    /usr/bin/ld: 找不到 -lmsc----解决方案 参考文章: (1)/usr/bin/ld: 找不到 -lmsc----解决方案 (2)https://www.cnblogs.com/fe ...

  5. cuda8.0 出错:/usr/bin/ld: 找不到 -lGL【转】

    本文转自:https://blog.csdn.net/u010159842/article/details/56833030 最近在学习深度学习,在搭建CUDA8.0的时候,出现一个非常不好的问题: ...

  6. /usr/bin/ld: 找不到 -lstdc++

    编译Linux工程,公司编译环境是CentOS5,可以正常编译.但移到CentOS7就不行了,总是提示: /usr/bin/ld: 找 不 到 -lstdc++ collect2: 错 误 : ld ...

  7. /usr/bin/ld:找不到 -lxxx

    编译时报错/usr/bin/ld:找不到 -lxxx 原因是找不到动态库 先定位libxxx.so文件位置: $ locate libxxx.so //如上述找不到 lcv_bridge, 则loca ...

  8. 【XMR】/usr/bin/ld: 找不到 -lstdc++

    [XMR]/usr/bin/ld: 找不到 -lstdc++ 报错明细 问题分析 解决办法 后记 报错明细 安装了Centos8.4 minimal版后对xmrig挖矿程序进行无抽水编译,执行: ma ...

  9. Linux下/usr/bin/ld: 找不到 -lz

    /usr/bin/ld: 找不到 -lz 在Ubuntu20.04下用Makefile编译c文件,首先要下载gcc. 首先进入root权限,输入密码(不会显示,输入回车就好了) 下载gcc apt-g ...

  10. 解决Make时,“/usr/bin/ld: 找不到 -lXXX”问题的四种方法

    比如: /usr/bin/ld: 找不到 -lboost_serialization 可能是英文: /usr/bin/ld:cannot find-lboost_serialization 意思是找不 ...

最新文章

  1. [C++调试笔记]网格划分grid_pic.cpp
  2. opencv python教程简书_OpenCV-Python教程:27.图像转换
  3. VTK:图片之ImageAnisotropicDiffusion2D
  4. python快速示例_Python编程入门-基本示例,快速,上,手,基础
  5. 我的助理辞职了!——给不听话的下属看看~
  6. Python之eval函数实例解释
  7. 023、JVM实战总结:一步一图:那JVM老年代垃圾回收器CMS工作时,内部又干了些啥?
  8. 把Sublime Text3从windwos移到ubunut上
  9. Windows下Mirth连接Sybase数据库
  10. html页面在线预览PDF文件
  11. 设置电脑保护视力的颜色
  12. Android 使用高德SDK编写周边搜索定位
  13. Unity实现Angry Bird弹弓发射功能
  14. java捕鱼达人程序设计_捕鱼达人(Java版)
  15. 该虚拟机似乎正在使用中
  16. 百度云虚拟机访问项目404
  17. BI 到底是什么,看看这篇文章怎么说
  18. clearcasse 命令
  19. 考古绘图中计算机的铺助应用,CAD和3D打印技术在文物考古中的应用研究
  20. 2022秋-北邮计导期末考试(BUPT大一上)

热门文章

  1. R-Sys.time计算程序运行时间
  2. android 创建文件夹,文件需要注意的格式
  3. 解决cacti创建ping主机时不出图的问题
  4. 禁止snmpd写入日志到syslog
  5. 网络工程师职业规划(三)
  6. 内网DNS地址自己定
  7. Eureka整合sidecar异构调用
  8. Problem D. Country Meow 2018ICPC南京
  9. linux查看cpu、内存、版本信息
  10. yum安装指定(特定)版本(旧版本)软件包的方法