h5fortran-mpi icon indicating copy to clipboard operation
h5fortran-mpi copied to clipboard

[Bug]: `*_openmpi_*` libraries cannot be found

Open MatthAlex opened this issue 8 months ago • 2 comments

Description

  • Linux Ubuntu 22.04
  • Compiler: Gfortran v11.4 & OpenMPI v4.1.2
  • HDF5: Compiled from source v1.14.6

Running an example driver causes a cascade of linking errors:

$ fpm run mpi_hdf5_test --profile release --compiler=mpif90 --flag -Dh5fortran_HAVE_PARALLEL --flag "-I/path/to/git/hdf5-1.14.6/hdf5/include -L/path/to/git/hdf5-1.14.6/hdf5/lib" --runner "mpirun -np 1"
mpi_hdf5_test                          failed.
[100%] Compiling...
/usr/bin/ld: missing --end-group; added as last command line option
/usr/bin/ld: cannot find -lhdf5_openmpihl_fortran: No such file or directory
/usr/bin/ld: cannot find -lhdf5_openmpi_fortran: No such file or directory
/usr/bin/ld: cannot find -lhdf5_openmpi_hl: No such file or directory
/usr/bin/ld: cannot find -lhdf5_openmpi: No such file or directory
collect2: error: ld returned 1 exit status
<ERROR> Compilation failed for object " mpi_hdf5_test "
<ERROR> stopping due to failed compilation
STOP 1

fpm.tom includes:

[build]
link = ["hdf5", "mpi"]
[dependencies]
h5fortran-mpi = { git="https://github.com/geospace-code/h5fortran-mpi.git"}
mpi = "*"

Workaround attempts

Checking under hdf5-1.14.6/hdf5/lib there are only these libraries:

$ ls /path/to/git/hdf5-1.14.6/hdf5/lib
libhdf5.a               libhdf5_fortran.so.310.3.2  libhdf5_hl_fortran.so         libhdf5_hl.so          libhdf5.so
libhdf5_fortran.a       libhdf5_hl.a                libhdf5hl_fortran.so          libhdf5_hl.so.310      libhdf5.so.310
libhdf5_fortran.la      libhdf5_hl_fortran.a        libhdf5hl_fortran.so.310      libhdf5_hl.so.310.0.6  libhdf5.so.310.5.1
libhdf5_fortran.so      libhdf5hl_fortran.a         libhdf5hl_fortran.so.310.0.6  libhdf5.la
libhdf5_fortran.so.310  libhdf5hl_fortran.la        libhdf5_hl.la                 libhdf5.settings
  • Adding link = ["hdf5hl_fortran", "hdf5_fortran", "hdf5", "mpi", "z"] to root fpm.toml produces the same error
  • Replacing the following directly under build/dependencies/h5fortran-mpi/fpm.toml:
- link = ["hdf5_openmpihl_fortran", "hdf5_openmpi_fortran", "hdf5_openmpi_hl", "hdf5_openmpi", "z", "mpi_mpifh", "mpi"]
+ link = ["hdf5hl_fortran", "hdf5_hl", "hdf5_fortran", "hdf5", "mpi", "z"]

fixes the problem

MatthAlex avatar Mar 26 '25 12:03 MatthAlex

This might be an FPM bug itself, this is the current way one is supposed to specify dependencies in a platform-independent way.

scivision avatar Jul 04 '25 02:07 scivision

I got it working by replacing link with the appropriate library names. Perhaps, I was fortunate to use a distribution of HDF5 which included a pkg config. I got the right package names by running:

pkg-config --list-all | grep hdf5 

And checked the correct library names by inspecting the compilation flags:

pkg-config --cflags --libs hdf5_fortran
pkg-config --cflags --libs hdf5_hl_fortran # My has an extra underscore

It would be nice if the library name could be resolved programmatically, or at least received as a sort of build parameter. But I agree that this is a limitation related to fpm.

lsmenicucci avatar Nov 03 '25 00:11 lsmenicucci