Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LD_LIBRARY_PATH not working while LD_PRELOAD works fine

Tags:

c++

c

linux

gcc

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?

like image 709
pythonic Avatar asked Dec 15 '22 16:12

pythonic


2 Answers

You need to give paths in LD_LIBRARY_PATH variable:

LD_LIBRARY_PATH=$PWD ./program args
like image 55
hyde Avatar answered Jan 07 '23 04:01

hyde


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.

like image 43
Mat Avatar answered Jan 07 '23 04:01

Mat