加载共享库时出错 [英] error while loading shared libraries

查看:214
本文介绍了加载共享库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目组织为

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

我的c程序 cmain 需要动态链接clib.so.4。当我编译代码时,我使用 -L ... / lib 来指示目录 lib ,并使用 -lxmlrpc_client ++ 。但是,我的代码在加载共享库时出错:

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:问题解决,对问题的很好参考: http ://gcc.gnu.org/ml/gcc-help/2005-12/msg00017html

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

推荐答案

你需要告诉动态链接器在哪里寻找库。假设这是某种UNIX / Linux系统,这可以通过在执行程序之前设置LD_LIBRARY_PATH环境变量来完成:

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

这两种方法都有问题。 Google为为什么LD_LIBRARY_PATH是坏。用于设置运行时链接器路径的命令行选项因编译器而异。

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.

这篇关于加载共享库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆