gpt4 book ai didi

linux - libmodbus.so.5 : cannot open shared object file: No such file or directory

转载 作者:太空宇宙 更新时间:2023-11-04 12:50:15 27 4
gpt4 key购买 nike

主机:Linux BBB-VirtualBox 3.19.0-25-generic#26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

目标:Linux beaglebone 3.8.13-bone70 #1 SMP Fri Jan 23 02:15:42 UTC 2015 armv7l GNU/Linux

我通过运行命令在主机上编译了 libmodbus:

./autogen.sh 
./configure --host=arm-linux-gnueabi --prefix=/home/BBB/build
sudo make
sudo make install

libinclude会生成在路径/home/BBB/build,复制到目标系统路径/usr/local 并运行 sudo ldconfig

然后我构建应用:

 arm-linux-gnueabi-gcc main.c $(pkg-config --libs --cflags ~/BBB/build/lib/pkgconfig/libmodbus.pc)

在目标上运行并返回错误:

root@beaglebone:~# ./a.out
./a.out: error while loading shared libraries: libmodbus.so.5: cannot open shared object file: No such file or directory

但是我可以在/usr/local/lib中找到libmodbus.so.5:

root@beaglebone:~# file a.out
a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0x4bc4bfa11806ebaffdd359ccf3a3144a4fda0a75, not stripped

root@beaglebone:~# find / -name "libmodbus*"
/usr/local/lib/libmodbus.so
/usr/local/lib/pkgconfig/libmodbus.pc
/usr/local/lib/libmodbus.la
/usr/local/lib/libmodbus.so.5.1.0
/usr/local/lib/libmodbus.so.5
/usr/local/include/libmodbus
......

我将库路径添加到 ld.so.confLD_LIBRARY_PATH 但仍然返回相同的错误。

root@beaglebone:~# cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
/usr/local/lib

root@beaglebone:~# echo $LD_LIBRARY_PATH
/usr/local/lib:

root@beaglebone:~# ldconfig -p | grep libmodbus
libmodbus.so.5 (libc6) => /usr/local/lib/libmodbus.so.5
libmodbus.so (libc6) => /usr/local/lib/libmodbus.so

我试过在编译app的时候加入-Wl,-rpath=/usr/local/lib,但是还是报错。

当我配置 libmodbus 并静态编译应用程序时,应用程序运行得非常好。

我该怎么办?

最佳答案

也许你可以试试

ldd a.out

在你的终端里看看是否所有的 .so 都找到了

我猜有任何 .so 没有找到。我遇到了这个问题,我通过在我的终端中输入 ldd some.object 解决了这个问题。我得到了类似的东西

linux-vdso.so.1 =>  (0x00007ffc32739000)
/usr/local/lib/libusb-driver.so (0x00007fb630a52000)
libmodbus.so.5 => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb630688000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb630484000)
libusb-0.1.so.4 => /lib/x86_64-linux-gnu/libusb-0.1.so.4 (0x00007fb63027b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb63005e000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb630c5a000)

可以看到,搜索目录不一定在目录/usr/local/lib

所以我将libmodbus.so.*添加到/lib/x86_64-linux-gnu/(在我的机器上,它可能与你的不同)。我明白了

linux-vdso.so.1 =>  (0x00007ffc2e9fe000)
/usr/local/lib/libusb-driver.so (0x00007fa2bbe36000)
libmodbus.so.5 => /lib/x86_64-linux-gnu/libmodbus.so.5 (0x00007fa2bbc2b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa2bb861000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa2bb65d000)
libusb-0.1.so.4 => /lib/x86_64-linux-gnu/libusb-0.1.so.4 (0x00007fa2bb454000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa2bb237000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa2bc03e000)

我解决了这个问题。

关于linux - libmodbus.so.5 : cannot open shared object file: No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37461451/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com