I wrote a shared object, say libsd.so
, and I put libsd.so
and its header file sd.h
in ~/lib
.
Here is another program using libsd.so
, say test.c
, then compile it like this:
$ gcc -o test test.c -I~/lib -L~/lib -lsd
Then I run test
like this:
$ ./test
./test_sd: error while loading shared libraries: libsd.so: cannot open shared object file: No such file or directory
So I set export LD_LIBRARY_PATH=.
, then it works. But if I unset LD_LIBRARY_PATH
and put LD_LIBRARY_PATH=~/lib
in my ~/.bashrc
, then source ~/.bashrc
, again it doesn't work for ./test
, WHY?
export LD_LIBRARY_PATH=~/lib
is difference from putting LD_LIBRARY_PATH=~/lib
in ~/.bashrc
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…