Reputation: 3
Based on this method, I can compile h5_crtdat.f90 through "gfortran h5_crtdat.f90 -fintrinsic-modules-path /usr/local/include -lhdf5_fortran" successfully. And I can run it as well.
Based on this method, I can compile h5_crtdat.f90 through "gfortran h5_crtdat.f90 -fintrinsic-modules-path /usr/local/include -lhdf5_fortran -Wl,-rpath,/usr/local/lib" successfully. However, after type in "./a.out" I got the following error "./a.out: error while loading shared libraries: libhdf5.so.200: cannot open shared object file: No such file or directory".
I have searched the google that these two methods can produce the same effect when linking shared library in gfortran compiler. Thus, I do not know why I will get the errors when the second method is used.
Upvotes: 0
Views: 241
Reputation: 59999
These two serve a different purpose.
LD_LIBRARY_PATH
says where to search for shared libraries when executing some executable that has already been compiled and linked. It is possible, but not guaranteed, that some linker will alsonconsider this path for the actual linking, but there are other variables, like LIBRARY_PATH
for that.
-Wl,-rpath
says where to link shared libraries when building the executable. It has no effect when running the executable.
You must set LD_LIBRARY_PATH
or some equivalent when running the executable so that the necessary libraries for the run can be located.
Upvotes: 2