I have a C++ file **a.cpp** with the library dependency in the path /home/name/lib and the name of the library **abc.so**.

I do the compilation as follows:

```
g++ a.cpp -L/home/name/lib -labc

```

This compiles the program with no errors. 
However while running the program, I get the ERROR:

./a.out: error while loading shared libraries: libabc.so.0: cannot open shared object file: No such file or directory

However if before running the program, I add the library path as

```
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/name/lib;

```

and compile and run now, it works fine.

**Why am I not able to link the library by giving it from the g++ command?**