0

I was trying to compile my code with Intel Fortran compiler in Ubuntu 20. My code needs HDF5 library, which I compiled separately, and I added the HDF5 library into LD_LIBRARY_PATH.After that, my LD_LIBRARY_PATH looks like this:

$ echo $LD_LIBRARY_PATH 
/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/rkcommon/1.11.0/lib:/opt/intel/oneapi/ospray_studio/0.12.0/lib:/opt/intel/oneapi/ospray/2.11.0/lib:/opt/intel/oneapi/openvkl/1.3.2/lib:/opt/intel/oneapi/oidn/1.4.3/lib:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ispc/1.19.0/lib:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/embree/4.0.1/lib:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/libipt/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp:“:/home/samz/local/lib/phdf5/1.8.23/build_ifort_2021_impi_2021/lib”

figure1

However, when I run my code, the Intel fortran compiler complains:

./****.exe: error while loading shared libraries: libhdf5_fortran.so.10: cannot open shared object file: No such file or directory

Whereas libhdf5_fortran.so.10 is in the /home/samz/local/lib/phdf5/1.8.23/build_ifort_2021_impi_2021/lib directory:

$ ls -la /home/samz/local/lib/phdf5/1.8.23/build_ifort_2021_impi_2021/lib
total 11420
drwxrwxr-x 2 samz samz    4096 Apr 10 14:35 .
drwxrwxr-x 6 samz samz    4096 Apr 10 14:35 ..
-rw-r--r-- 1 samz samz 6763194 Apr 10 14:35 libhdf5.a
-rw-r--r-- 1 samz samz  419748 Apr 10 14:35 libhdf5_fortran.a
-rwxr-xr-x 1 samz samz    1115 Apr 10 14:35 libhdf5_fortran.la
lrwxrwxrwx 1 samz samz      25 Apr 10 14:35 libhdf5_fortran.so -> libhdf5_fortran.so.10.0.8
lrwxrwxrwx 1 samz samz      25 Apr 10 14:35 libhdf5_fortran.so.10 -> libhdf5_fortran.so.10.0.8
-rwxr-xr-x 1 samz samz  341456 Apr 10 14:35 libhdf5_fortran.so.10.0.8
-rw-r--r-- 1 samz samz  229896 Apr 10 14:35 libhdf5_hl.a
lrwxrwxrwx 1 samz samz      19 Apr 10 14:35 libhdf5_hl_fortran.a -> libhdf5hl_fortran.a
-rw-r--r-- 1 samz samz  127576 Apr 10 14:35 libhdf5hl_fortran.a
-rwxr-xr-x 1 samz samz    1292 Apr 10 14:35 libhdf5hl_fortran.la
lrwxrwxrwx 1 samz samz      20 Apr 10 14:35 libhdf5_hl_fortran.so -> libhdf5hl_fortran.so
lrwxrwxrwx 1 samz samz      27 Apr 10 14:35 libhdf5hl_fortran.so -> libhdf5hl_fortran.so.10.0.7
lrwxrwxrwx 1 samz samz      27 Apr 10 14:35 libhdf5hl_fortran.so.10 -> libhdf5hl_fortran.so.10.0.7
-rwxr-xr-x 1 samz samz  106024 Apr 10 14:35 libhdf5hl_fortran.so.10.0.7
-rwxr-xr-x 1 samz samz    1080 Apr 10 14:35 libhdf5_hl.la
lrwxrwxrwx 1 samz samz      20 Apr 10 14:35 libhdf5_hl.so -> libhdf5_hl.so.10.2.4
lrwxrwxrwx 1 samz samz      20 Apr 10 14:35 libhdf5_hl.so.10 -> libhdf5_hl.so.10.2.4
-rwxr-xr-x 1 samz samz  163408 Apr 10 14:35 libhdf5_hl.so.10.2.4
-rwxr-xr-x 1 samz samz     983 Apr 10 14:35 libhdf5.la
-rw-r--r-- 1 samz samz    6699 Apr 10 14:35 libhdf5.settings
lrwxrwxrwx 1 samz samz      17 Apr 10 14:35 libhdf5.so -> libhdf5.so.10.4.1
lrwxrwxrwx 1 samz samz      17 Apr 10 14:35 libhdf5.so.10 -> libhdf5.so.10.4.1
-rwxr-xr-x 1 samz samz 3491568 Apr 10 14:35 libhdf5.so.10.4.1

Then I used the option export LD_DEBUG=all to debug the problem and figured out the problem was that the added HDF5 library path is not actually checked. Here are the extracts from the output of the LD_DEBUG mode:

...
126670:  search path=/opt/intel/oneapi/tbb/2021.9.0/env/../lib/intel64/gcc4.8:/opt/intel/oneapi/rkcommon/1.11.0/lib:/opt/intel/oneapi/ospray_studio/0.12.0/lib:/opt/intel/oneapi/ospray/2.11.0/lib:/opt/intel/oneapi/openvkl/1.3.2/lib:/opt/intel/oneapi/oidn/1.4.3/lib:/opt/intel/oneapi/mpi/2021.9.0//libfabric/lib:/opt/intel/oneapi/mpi/2021.9.0//lib/release:/opt/intel/oneapi/mpi/2021.9.0//lib:/opt/intel/oneapi/mkl/2023.1.0/lib/intel64:/opt/intel/oneapi/itac/2021.9.0/slib:/opt/intel/oneapi/ispc/1.19.0/lib:/opt/intel/oneapi/ipp/2021.8.0/lib/intel64:/opt/intel/oneapi/ippcp/2021.7.0/lib/intel64:/opt/intel/oneapi/embree/4.0.1/lib:/opt/intel/oneapi/dnnl/2023.1.0/cpu_dpcpp_gpu_dpcpp/lib:/opt/intel/oneapi/debugger/2023.1.0/gdb/intel64/lib:/opt/intel/oneapi/debugger/2023.1.0/dep/lib:/opt/intel/oneapi/dal/2023.1.0/lib/intel64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/x64:/opt/intel/oneapi/compiler/2023.1.0/linux/lib/oclfpga/host/linux64/lib:/opt/intel/oneapi/compiler/2023.1.0/linux/compiler/lib/intel64_lin:/opt/intel/oneapi/ccl/2021.9.0/lib/cpu_gpu_dpcpp:“/tls/haswell/x86_64:“/tls/haswell:“/tls/x86_64:“/tls:“/haswell/x86_64:“/haswell:“/x86_64:“        (LD_LIBRARY_PATH)
...

figure2

I was able to work around by creating links to the HDF5 library at the directories that are actually checked by the code. But wondering why changing the LD_LIBRARY_PATH did not work?

I loaded the Intel environment in .bashrc via . /opt/intel/oneapi/setvars.sh > /dev/null

Appreciate your helps. Thank you.

Sam Z
  • 1
  • 1
  • The libhdf5 library is not inside the oneAPI installation, there is no reason why the oneAPI environement should see it. Also, `LD_LIBRARY_PATH` is for the runtime linker. Try adding the path to your library to `LIBRARY_PATH` or supplying the path using the `-L` flag. – Vladimir F Героям слава Apr 11 '23 at 05:47
  • @Vladimir F Героям слава Adding the path to your library to `LIBRARY_PATH` didn't help. The error happens when I run the program, not when I was linking it. Also I tried `./****.exe -L/home/samz/local/lib/phdf5/1.8.23/build_ifort_2021_impi_2021/lib` and it also didn't work. Any idea? – Sam Z Apr 12 '23 at 14:38
  • Oh, sorry, you are right, it is a runtime error. In that case the things to use are indeed `LD_LIBRARY_PATH` and `/etc/ld.so.conf.d` together with `ldconfig`. – Vladimir F Героям слава Apr 12 '23 at 14:40
  • However, when I quickly glanced over the first snippet in your question, the one that defines `LD_LIBRARY_PATH`, it seems to me you are doing it wrong. You should just use `:/home/samz/local/lib/phdf5/1.8.23/build_ifort_2021_impi_2021/lib` and not `:“:/home/samz/local/lib/phdf5/1.8.23/build_ifort_2021_impi_2021/lib”`. The double colon is not a part of the path. – Vladimir F Героям слава Apr 12 '23 at 14:43
  • @VladimirFГероямслава Thank you very much! I think I have figured that out. You are right, the quotation mark is the problem. It is weird that in Mac I can do `export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HDF5_DIR/lib"`, but in Ubuntu I must do it without the quotation mark. – Sam Z Apr 12 '23 at 14:56

0 Answers0