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?
Without the export your declared LD_LIBRARY_PATH is only valid in the script (.bashrc).
With the export it should work, but it is usually not a good idea to set your LD_LIBRARY_PATH like this.
If you don’t want to install your library in the system path (e.g. /usr/lib) you should probably use a script that sets LD_LIBARAY_PATH locally and starts your application.