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.
In Linux, the environment variable LD_LIBRARY_PATH is a colon-separated set of directories where libraries should be searched for first, before the standard set of directories; this is useful when debugging a new library or using a nonstandard library for special purposes.
The LD_LIBRARY_PATH environment variable tells Linux applications, such as the JVM, where to find shared libraries when they are located in a different directory from the directory that is specified in the header section of the program.
In your terminal, type the following sudo ldconfig and press enter on your keyboard. Close all your open terminals that you were using then open a new terminal session and run echo $LD_LIBRARY_PATH If you see the path you added is echoed back, you did it right.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With