简体   繁体   中英

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

Host: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

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

I was compiled libmodbus on host, by running command:

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

and lib and include will be generated in path /home/BBB/build ,copied to target system path /usr/local and run sudo ldconfig .

then I build application :

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

running on target and it return error:

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

but I can find libmodbus.so.5 in /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
......

I add the lib path to ld.so.conf and LD_LIBRARY_PATH but still return same error.

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

I tried add -Wl,-rpath=/usr/local/lib when compiling app,but still return error.

When I config libmodbus and compile app statically,the app running very well.

What should I do?

maybe you can try

ldd a.out

in your terminal and see whether all .so found

I guest there are any .so not found. I have encountered this problem and I solve that by typing ldd some.object in my terminal. And I get something like that

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)

as you can see, the search directory is not necessarily in the directory /usr/local/lib

So I add libmodbus.so.* into /lib/x86_64-linux-gnu/ (in my machine, it can be different from yours). I get

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)

And I solve this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM