设置用于在运行时加载共享库的LD_LIBRARY_PATH环境变量(g ++) [英] Setting LD_LIBRARY_PATH environment variable for loading a shared library at runtime (g++)
问题描述
我有两个相同问题的问题:
-
我有一个共享对象保存在`pwd` / lib,而使用它的可执行文件成功编译(通过使用-l和-L开关),在运行时它给我的悲伤。如果我尝试运行
LD_LIBRARY_PATH = / my / absolute / path / to / library / directory ./test
它工作正常。但是如果我导出LD_LIBRARY_PATH = / my / absolute / path /到/ library /目录,并且执行./ test
,它表示它找不到共享库。但是,如果我执行LD_LIBRARY_PATH = $ LD_LIBRARY_PATH ./test
再次它工作正常!关于我做错什么的任何想法? -
第二个问题与导出LD_LIBRARY_PATH env变量有关。如果我打开一个终端,输入
导出LD_LIBRARY_PATH = / path / to / stuff
然后键入echo $ LD_LIBRARY_PATH
变量是正确的。但是,如果我写一个包含导出命令的脚本,只需运行它就不会更新变量,而是需要运行source install.sh
,以便实际保持变量。这是最好的解决方案?
谢谢你的时间!
首先回答第二个问题:
source
执行当前shell中的脚本, ./ install.sh
打开并在不同的shell中执行。
http:/ /www.unix.com/unix-dummies-questions-answers/537-difference-between-source-exec-script.html
现在为您的第一个问题:
LD_LIBRARY_PATH = $ LD_LIBRARY_PATH ./test
在只有一个命令之前设置LD_LIBRARY_PATH变量( ./ test
命令)。由于上述相同的原因,我相信这没有被转移到任何shell ./ test
创建。要使其持续存在,您可能需要将导出LD_LIBRARY_PATH = ...
放在您的〜/ .bashrc
/ p>
I'm having two problems related to the same issue:
I have a shared object saved in `pwd`/lib and while the executable that uses it compiles successfully (by using -l and -L switches), at runtime, it's giving me grief. If I try to run
LD_LIBRARY_PATH=/my/absolute/path/to/library/directory ./test
it works fine. But if I export LD_LIBRARY_PATH=/my/absolute/path/to/library/directory and do./test
it says that it can't find the shared library. However, if I doLD_LIBRARY_PATH=$LD_LIBRARY_PATH ./test
again it works fine!! Any ideas on what I'm doing wrong?Second issue is related to the exporting of the LD_LIBRARY_PATH env variable. If I open a terminal and type
export LD_LIBRARY_PATH=/path/to/stuff
and then typeecho $LD_LIBRARY_PATH
, the variable is correct. However if I write a script containing the export command, simply running it doesn't update the variable, instead I need to runsource install.sh
in order to actually persist the variable. What's the best solution for this?
Thank you for your time!
To answer the second question first:
source
executes the script inside the current shell, ./install.sh
opens and executes it in a different shell.
http://www.unix.com/unix-dummies-questions-answers/537-difference-between-source-exec-script.html
Now for your first question:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./test
sets the LD_LIBRARY_PATH variable before just one command (the ./test
command). For the same reason above, I believe this isn't getting transferred to whatever shell ./test
creates. To make it persist, you may need to put the export LD_LIBRARY_PATH=...
in your ~/.bashrc
这篇关于设置用于在运行时加载共享库的LD_LIBRARY_PATH环境变量(g ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!