为什么一旦加载可执行文件,运行时LD_LIBRARY_PATH中的更改就不会反映在可执行文件上 [英] Why change in LD_LIBRARY_PATH at Runtime dosen't Reflect on the Executable once the Executable gets loaded
问题描述
我正在尝试从C ++程序更改LD_LIBRARY_PATH
.我可以使用getenv("LD_LIBRARY_PATH")
获取其值,并使用 setenv()
(而且我知道这是可行的,因为当我再次调用getenv("LD_LIBRARY_PATH")
时,会得到更新的值),但是从程序内部更改其值不会对其产生任何影响:我仍然收到此错误消息:
I'm trying to change the LD_LIBRARY_PATH
from my C++ program. I'm able to get its value using getenv("LD_LIBRARY_PATH")
and set its value using setenv()
(and I know that this is working, because when I call getenv("LD_LIBRARY_PATH")
again, I get the updated value), but changing its value from inside the program isn't having any effect on it: I still get this error-message:
Failed to Load the shared library file
如果我在加载可执行文件或启动应用程序之前设置该值,那么它将正常工作.
If I set the value before the executable gets loaded or the application is started, it works fine.
推荐答案
不幸的是,从正在运行的程序中设置LD_LIBRARY_PATH
不会对其产生影响.原因是LD_LIBRARY_PATH
由动态链接加载程序(ld.so)处理,这是启动程序的程序.您的程序本身不会处理LD_LIBRARY_PATH
,因此对其进行更改将无效.
Unfortunately setting LD_LIBRARY_PATH
from within a running program will have no effect on it. The reason for this is that LD_LIBRARY_PATH
is processed by the dynamic link loader (ld.so), which is the program which starts your program. Your program itself doesn't process LD_LIBRARY_PATH
so changing it will have no effect.
这篇关于为什么一旦加载可执行文件,运行时LD_LIBRARY_PATH中的更改就不会反映在可执行文件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!