Error with shared lIBMpi.so.1 when compiling CPP program

Hello,
Met a problem when compiling a C++ program from source code without error, but when ran it there was always an error message:

./Ray: error while loading shared libraries: libmpi_cxx.so.1: cannot open shared object file: No such file or directory

As the error points to openmpi which was installed at /usr/lib64/openmpi/bin/mpicxx

$ locate libmpi_cxx.so.1
$ /usr/lib64/openmpi/lib/libmpi_cxx.so.1

Then I did following without enough understanding

export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH

and compile again. It worked!
Now my questions are:
1) When should I export the shared libraries, especially when the shared library is installed at a local directory?
2) Is there any rule to find out any shared library is needed for the compilation of a program besides the system ones /lib:usr/lib:usr/local/lib ?
I guessed out the needed library for my example is located at /usr/lib64/openmpi/lib as mpicxx is located at
/usr/lib64/openmpi/bin/
Thanks a lot!