18.04.03 lts版本,多级连接SO无法使用

C、C++和Java语言
回复
aaadddzxc
帖子: 148
注册时间: 2011-04-30 23:10
送出感谢: 0
接收感谢: 0

18.04.03 lts版本,多级连接SO无法使用

#1

帖子 aaadddzxc » 2020-01-09 11:52

看我附件,a b c三个模块
a 依赖 b
c 依赖 a
ldd c 无法找到a.so
编译出来的程序也提示无法找到a.so

咋个弄的?谁知道
执行运行make.sh 就能自动编译了
附件
123.tar.xz
(572 Bytes) 下载 23 次
头像
astolia
论坛版主
帖子: 4417
注册时间: 2008-09-18 13:11
送出感谢: 1 次
接收感谢: 739 次

Re: 18.04.03 lts版本,多级连接SO无法使用

#2

帖子 astolia » 2020-01-10 11:54

我在18.04.3上编译链接无任何报错。运行程序说无法找到libbmodule.so,也属正常。

代码: 全选

/tmp/123$ ls
1  2  4.c  make.sh
/tmp/123$ ./make.sh 
/tmp/123$ ./a.out
./a.out: error while loading shared libraries: libbmodule.so: cannot open shared object file: No such file or directory
因为你给rpath传递的是相对路径,是相对于当前目录,而非当前文件所在目录。
你在a.out所在目录执行程序,需要找libbmodule.so时,是用的libcmodule.so里的rpath数据,即../1
而当前目录的上级并无1这个目录,所以就找不到了

设置LD_DEBUG环境变量来查看运行时的搜索路径,能看得更清楚

代码: 全选

LD_DEBUG=libs ./a.out
/tmp/123$ LD_DEBUG=libs ./a.out
26362: find library=libcmodule.so [0]; searching
26362: search path=./2/tls/x86_64/x86_64:./2/tls/x86_64:./2/tls/x86_64:./2/tls:./2/x86_64/x86_64:./2/x86_64:./2/x86_64:./2:./1/tls/x86_64/x86_64:./1/tls/x86_64:./1/tls/x86_64:./1/tls:./1/x86_64/x86_64:./1/x86_64:./1/x86_64:./1 (RUNPATH from file ./a.out)
26362: trying file=./2/tls/x86_64/x86_64/libcmodule.so
26362: trying file=./2/tls/x86_64/libcmodule.so
26362: trying file=./2/tls/x86_64/libcmodule.so
26362: trying file=./2/tls/libcmodule.so
26362: trying file=./2/x86_64/x86_64/libcmodule.so
26362: trying file=./2/x86_64/libcmodule.so
26362: trying file=./2/x86_64/libcmodule.so
26362: trying file=./2/libcmodule.so
26362:
26362: find library=libc.so.6 [0]; searching
26362: search path=./2/tls/x86_64/x86_64:./2/tls/x86_64:./2/tls/x86_64:./2/tls:./2/x86_64/x86_64:./2/x86_64:./2/x86_64:./2:./1/tls/x86_64/x86_64:./1/tls/x86_64:./1/tls/x86_64:./1/tls:./1/x86_64/x86_64:./1/x86_64:./1/x86_64:./1 (RUNPATH from file ./a.out)
26362: trying file=./2/tls/x86_64/x86_64/libc.so.6
26362: trying file=./2/tls/x86_64/libc.so.6
26362: trying file=./2/tls/x86_64/libc.so.6
26362: trying file=./2/tls/libc.so.6
26362: trying file=./2/x86_64/x86_64/libc.so.6
26362: trying file=./2/x86_64/libc.so.6
26362: trying file=./2/x86_64/libc.so.6
26362: trying file=./2/libc.so.6
26362: trying file=./1/tls/x86_64/x86_64/libc.so.6
26362: trying file=./1/tls/x86_64/libc.so.6
26362: trying file=./1/tls/x86_64/libc.so.6
26362: trying file=./1/tls/libc.so.6
26362: trying file=./1/x86_64/x86_64/libc.so.6
26362: trying file=./1/x86_64/libc.so.6
26362: trying file=./1/x86_64/libc.so.6
26362: trying file=./1/libc.so.6
26362: search cache=/etc/ld.so.cache
26362: trying file=/lib/x86_64-linux-gnu/libc.so.6
26362:
26362: find library=libbmodule.so [0]; searching
26362: search path=../1/tls/x86_64/x86_64:../1/tls/x86_64:../1/tls/x86_64:../1/tls:../1/x86_64/x86_64:../1/x86_64:../1/x86_64:../1 (RUNPATH from file ./2/libcmodule.so)

26362: trying file=../1/tls/x86_64/x86_64/libbmodule.so
26362: trying file=../1/tls/x86_64/libbmodule.so
26362: trying file=../1/tls/x86_64/libbmodule.so
26362: trying file=../1/tls/libbmodule.so
26362: trying file=../1/x86_64/x86_64/libbmodule.so
26362: trying file=../1/x86_64/libbmodule.so
26362: trying file=../1/x86_64/libbmodule.so
26362: trying file=../1/libbmodule.so
26362: search cache=/etc/ld.so.cache
26362: search path=/lib/x86_64-linux-gnu/tls/x86_64/x86_64:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls:/lib/x86_64-linux-gnu/x86_64/x86_64:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/tls/x86_64/x86_64:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls:/usr/lib/x86_64-linux-gnu/x86_64/x86_64:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu:/lib/tls/x86_64/x86_64:/lib/tls/x86_64:/lib/tls/x86_64:/lib/tls:/lib/x86_64/x86_64:/lib/x86_64:/lib/x86_64:/lib:/usr/lib/tls/x86_64/x86_64:/usr/lib/tls/x86_64:/usr/lib/tls/x86_64:/usr/lib/tls:/usr/lib/x86_64/x86_64:/usr/lib/x86_64:/usr/lib/x86_64:/usr/lib (system search path)
26362: trying file=/lib/x86_64-linux-gnu/tls/x86_64/x86_64/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/tls/x86_64/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/tls/x86_64/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/tls/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/x86_64/x86_64/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/x86_64/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/x86_64/libbmodule.so
26362: trying file=/lib/x86_64-linux-gnu/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/tls/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/x86_64/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64-linux-gnu/libbmodule.so
26362: trying file=/lib/tls/x86_64/x86_64/libbmodule.so
26362: trying file=/lib/tls/x86_64/libbmodule.so
26362: trying file=/lib/tls/x86_64/libbmodule.so
26362: trying file=/lib/tls/libbmodule.so
26362: trying file=/lib/x86_64/x86_64/libbmodule.so
26362: trying file=/lib/x86_64/libbmodule.so
26362: trying file=/lib/x86_64/libbmodule.so
26362: trying file=/lib/libbmodule.so
26362: trying file=/usr/lib/tls/x86_64/x86_64/libbmodule.so
26362: trying file=/usr/lib/tls/x86_64/libbmodule.so
26362: trying file=/usr/lib/tls/x86_64/libbmodule.so
26362: trying file=/usr/lib/tls/libbmodule.so
26362: trying file=/usr/lib/x86_64/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64/libbmodule.so
26362: trying file=/usr/lib/x86_64/libbmodule.so
26362: trying file=/usr/lib/libbmodule.so
26362:
./a.out: error while loading shared libraries: libbmodule.so: cannot open shared object file: No such file or directory
回复

回到 “C/C++/Java”