I am trying to compile one of the projects found here USB-I2C/SPI/GPIO Interface Adapter.
I downloaded the i2c_bridge-0.0.1-rc2.tgz
package. I installed libusb
and that seemed to go well with no issues. I go into the i2c_bridge-0.0.1-rc2/
directory and make. That compiles. I move into the i2c_bridge-0.0.1-rc2/i2c
folder and make. It compiles and gives me ./i2c
. However, when I run it, it says error while loading shared libraries: libi2cbrdg.so: cannot open shared object file: No such file or directory
The makefile in i2c_bridge-0.0.1-rc2/i2c
has the library directory as ../
. The libi2cbrdg.so
is in this directory (i2c_bridge-0.0.1-rc2
). I also copied the file to /usr/local/lib
. An ls
of the i2c_bridge-0.0.1-rc2/
directory is
i2c i2cbrdg.d i2cbrdg.o libi2cbrdg.a Makefile tests
i2cbrdg.c i2cbrdg.h INSTALL libi2cbrdg.so README u2c4all.sh
(That i2c
is a directory)
If I sudo ./i2c
, it still gives me the problem.
I had to take away the -Werror
and -noWdecrepated
(spelling?) options in all the makefiles to get them to compile, but that shouldn't affect this should it?
What else is necessary for it to find the .so
file? If anyone can help me find out what is wrong I would be very grateful. If more information is needed I can post it.
Sometimes, the shared library might not exist or might be located in a non-standard path. As a result, we get the “cannot open shared object file: No such file or directory” at program launch.
Fix ing 'cannot open shared object file: No such file or directory' error. One quick way to fix this “error while loading shared libraries” automatically is to use ldconfig. This one liner should solve the problem in most cases.
If you want to open a shared-library file, you would open it like any other binary file -- with a hex-editor (also called a binary-editor). There are several hex-editors in the standard repositories such as GHex (https://packages.ubuntu.com/xenial/ghex) or Bless (https://packages.ubuntu.com/xenial/bless).
so file is a binary file used as a native library on Android. Normally it's a part of an Android application. If you want to see its content, you need to open it as a binary file in a binary (hex) viewer. In any case you won't see much there, but hex code.
You have to distinguish between finding so
's at compile-time and at run-time. The -L
flag you give at compile-time has nothing to do with localizing the library at run-time. This is rather done via a number of variables and some paths embedded in the library.
The best hot-fix for this problem is often setting LD_LIBRARY_PATH to the directory with the .so
file, e.g.:
$ LD_LIBRARY_PATH=.. ./i2c
For a long-term solution, you need to either have a close look at the whole LD system with rpath
and runpath
, or use libtool
(which solves these issues for your portably).
Copying a file to /usr/local/lib
is often insufficient because ld
caches the available libraries, so you need to re-run ldconfig
(as root) after you copied a library to /usr/local/lib
.
If you are building the code from source that needs the the library, you can put the path that the library is in in the environment variable LD_RUN_PATH before building, and the linker will save that path into the binary, so that it will automatically be looked for in the right place at runtime.
Linux specific: Alternately, put the library in /lib
, /usr/lib
, or some other path referenced in your /etc/ld.so.conf
or its imported config fragments, and then all you need to do is run /sbin/ldconfig
to refresh ld.so (the dynamic linker)'s cache of libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With