Why change in LD_LIBRARY_PATH at Runtime dosen't Reflect on the Executable once the Executable gets loaded

StackOverflow https://stackoverflow.com/questions/19337926

  •  30-06-2022
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top