Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error while loading shared libraries

Tags:

c++

c

linker

I have a project organized as

\bin\cmain
\lib\libxmlrpc_client++.a
\lib\libxmlrpc_client++.so.4
\lib\libxmlrpc_client++.so.4.16

My c program cmain need to dynamically link clib.so.4. While I compile the code, I use -L.../lib to indicate directory lib and use -lxmlrpc_client++. However, my code get error while loading shared libraries:

libxmlrpc_client++.so.4: cannot open shared object file: No such file or directory

Any ideas to fix this?

PS: Problem solved, a good reference to the problem: http://gcc.gnu.org/ml/gcc-help/2005-12/msg00017.html

like image 577
Richard Avatar asked Mar 18 '11 21:03

Richard


People also ask

How do I load a shared library?

Once you've created a shared library, you'll want to install it. The simple approach is simply to copy the library into one of the standard directories (e.g., /usr/lib) and run ldconfig(8). Finally, when you compile your programs, you'll need to tell the linker about any static and shared libraries that you're using.

Could not load library Cannot open shared object file no such file or directory?

cannot open shared object file: No such file or directory The reason behind this error is that the libraries of the program have been installed in a place where dynamic linker cannot find it.

What is Cannot open shared object file?

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.

How do I open a shared library in Linux?

You need to run the ldconfig command to effect the changes. After creating your shared library, you need to install it. You can either move it into any of the standard directories mentioned above and run the ldconfig command.


1 Answers

You need to tell the dynamic linker where to look for the libraries. Assuming this is some sort of UNIX/Linux system, this can be done either via setting the LD_LIBRARY_PATH environment variable before executing the program:

export LD_LIBRARY_PATH=/path/to/lib
./run-my-program

or by setting the run-time linker path during compile time:

gcc -L/path/to/lib -Wl,-rpath,/path/to/lib -lxmlrpc_client++ ...
./run-my-program

Both approaches have problems. Google for "why LD_LIBRARY_PATH is bad". The command-line options for setting the run-time linker path varies from one compiler to another.

like image 67
Scott Duckworth Avatar answered Sep 29 '22 21:09

Scott Duckworth