Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"cannot open shared object file," but it exists

Tags:

c++

.so

I'm having trouble finding why this library (matio) isn't working for me. In my Makefile I have this:

LIBS += -L/home/brian/.../matio-1.5.6/src/.libs/ -lmatio

When I attempt to run my code (links fine) I get this error:

error while loading shared libraries: libmatio.so.4: cannot open shared object file: No such file or directory

libmatio.so.4 exists in the directory specified by the -L flag.

I built the library and it seems to go through make check with only a handful writing errors (which is fine as I only need it for reading).

Things I've tried:

  • Specifying the name (i.e. -l:libmatio.so.4.0.2)
  • Adding the path to LD_LIBRARY_PATH
  • Adding the path as a line in /etc/ld.so.conf and run sudo ldconfig
  • Adding a new file in /etc/ld.so.conf.d with the path and run sudo ldconfig

(When I run ldconfig -p | grep matio nothing returns. Am I doing something wrong with ldconfig?)

like image 508
brian Avatar asked Mar 10 '16 22:03

brian


People also ask

How do I open a .so file in Unix?

SO files can technically be opened with GNU Compiler Collection but these types of files aren't intended to be viewed or used like you might another type of file. Instead, they're just placed in an appropriate folder and used automatically by other programs via Linux's dynamic link loader.

How do I open a shared library file?

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


1 Answers

The error is actually telling you "no compatible library with that name exists in the library cache", not "no file with that filename exists on disk".

So, confusingly, this can happen when the shared object file is in the wrong format.

Ensure that it was built for the right platform by the right compiler! You can have a look with file and verify that the dynamic link is failing using ldd on your executable.

like image 141
Lightness Races in Orbit Avatar answered Oct 30 '22 01:10

Lightness Races in Orbit