I am compiling a program on one machine and running it on another one which does not have compatible libstdc++ library. If I run it like this, that is using LD_PRELOAD, it runs fine.
LD_PRELOAD=./libstdc++.so.6 ./program args
However, If I try to use LD_LIBRARY_PATH, like shown below, it doesn't load the library and I get the error that I don't have the required libstdc++ version.
export LD_LIBRARY_PATH="./libstdc++.so.6"
./program args
How can I solve this problem?
You need to give paths in LD_LIBRARY_PATH variable:
LD_LIBRARY_PATH=$PWD ./program args
LD_LIBRARY_PATH
, like PATH
, takes a list of directories, not files.
If you want to put the current directory (not recommended) in there, you can:
export LD_LIBRARY_PATH=.
But it is always better to put absolute paths in there so that you don't pick up random garbage if you change directories.
For your specific problem, keeping LD_PRELOAD
might actually be the best way to do it in case your executable has rpath
settings (which might override the environment). Create a wrapper script that does it if you don't want to re-type it every time.
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