简体   繁体   中英

error while loading shared libraries

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

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.

You should use -Llib instead of -L. .

Is that softlink broken? ls -l, make sure your pointing to the correct file.

Example Error:

[root@localhost ~]#./conn 127.0.0.1 6379 opencc./conn: error while loading shared libraries: libhiredis.so.1.0.3-dev: cannot open shared object file: No such file or directory

Solution

The problem was the libhiredis wasn't in the ldconfig path. While the build process was correct and it copied everything to the correct directory ldconfig did not know about its location.

You can use ldconfig -p to see all library ldconfig currently know about.

You can add the path to ldconfig with

sudo echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf

&

sudo ldconfig

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