libmodbus.so.5:无法打开共享对象文件:没有这样的文件或目录

时间:2016-05-26 12:53:08

标签: linux shared-libraries cross-compiling beagleboneblack

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

目标:Linux beaglebone 3.8.13-bone70#1 SMP Fri 1月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

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

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
......

我将lib路径添加到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

我在编译应用时尝试添加-Wl,-rpath=/usr/local/lib,但仍然会返回错误。

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

我该怎么办?

1 个答案:

答案 0 :(得分:0)

也许您可以尝试

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)

我解决了这个问题。