问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/19337926/why-change-in-ld-library-path-at-runtime-dosent-reflect-on-the-executable-once