我为什么要每次运行我的应用程序的时间定义与出口LD_LIBRARY_PATH? [英] Why do I have to define LD_LIBRARY_PATH with an export every time I run my application?
问题描述
我有一个使用一些共享库(海合会C code)部分code。编译当我有明确的定义包括使用-I和-L,因为它们不是标准的地方库目录。当我尝试运行code,我得到以下错误:
./ sync_test
./sync_test:错误而载入共享库:libsync.so:无法打开共享对象文件:没有这样的文件或目录
然而,做到以下几点,一切工作就好了:
出口LD_LIBRARY_PATH =/路径/要/库/
./sync_test
现在,奇怪的部分是,这只能使用一次。如果我尝试运行sync_test我再次得到了同样的错误,除非我先运行export命令。我尝试添加以下到我的.bashrc,但它并没有区别:
LD_LIBRARY_PATH =/路径/要/库/
使用
出口LD_LIBRARY_PATH =/路径/要/库/
在你的.bashrc否则,它会只提供给bash和不启动任何程序。
尝试 -R /路径/要/库/
当你链接,它会让该目录中的程序看,你会不会需要标志设置任何环境变量。
编辑:看起来像 -R
是仅Solaris,而你在Linux
这是另一种方法是将路径添加到 /etc/ld.so.conf中
并运行 ldconfig的
。请注意,这是一个将适用于所有动态链接的二进制文件的全球变化。
I have some code that uses some shared libraries (c code on gcc). When compiling I have to explicitly define the include and library directories using -I and -L, since they aren't in the standard places. When I try to run the code, I get the following error:
./sync_test
./sync_test: error while loading shared libraries: libsync.so: cannot open shared object file: No such file or directory
However, do the following, everything works just fine:
export LD_LIBRARY_PATH="/path/to/library/"
./sync_test
Now, the strange part is, this only works once. If I try and run sync_test again I get the same error unless I run the export command first. I tried adding the following to my .bashrc, but it made no difference:
LD_LIBRARY_PATH="/path/to/library/"
Use
export LD_LIBRARY_PATH="/path/to/library/"
in your .bashrc otherwise, it'll only be available to bash and not any programs you start.
Try -R/path/to/library/
flag when you're linking, it'll make the program look in that directory and you won't need to set any environment variables.
EDIT: Looks like -R
is Solaris only, and you're on Linux.
An alternate way would be to add the path to /etc/ld.so.conf
and run ldconfig
. Note that this is a global change that will apply to all dynamically linked binaries.
这篇关于我为什么要每次运行我的应用程序的时间定义与出口LD_LIBRARY_PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!