加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 为什么GNU链接器找不到带-l的共享对象?

发布时间:2020-12-14 02:12:04 所属栏目:Linux 来源:网络整理
导读:我在尝试链接目标文件时遇到错误: $g++ -o intro intro.o -L -Wl,-rpath-link -lnotes -lm -lnsl -lpthread -lc -lresolv -ldl/usr/bin/ld: cannot find -lnotescollect2: ld returned 1 exit status 但是,库似乎就在那里(事实上,我把它放在那里通过将/ opt
我在尝试链接目标文件时遇到错误:

$g++ -o intro intro.o -L -Wl,-rpath-link  -lnotes -lm -lnsl -lpthread -lc -lresolv -ldl
/usr/bin/ld: cannot find -lnotes
collect2: ld returned 1 exit status

但是,库似乎就在那里(事实上,我把它放在那里通过将/ opt / ibm / lotus / notes包含在/etc/ld.so.conf.d/中的文件中并运行ldconfig):

$ldconfig --print-cache | grep libnotes                                                      
361:    libnoteswc.so (libc6) => /opt/ibm/lotus/notes/libnoteswc.so
362:    libnotes.so (libc6) => /opt/ibm/lotus/notes/libnotes.so

为什么链接失败以及如何使链接器使用这些共享对象?

解决方法

GCC does not specify a runpath so that the dynamic linker can find dynamic libraries at runtime…Yet another option,that works on a few platforms,is to hard-code the full pathname of the library into its soname. This can only be accomplished by modifying the appropriate .ml file within libstdc++/config (and also libg++/config,if you are building libg++),so that $(libdir)/ appears just before the library name in -soname or -h options.

http://gcc.gnu.org/faq.html#rpath

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读