TL&DR: When HDF_IS_PARALLEL
is true, one needs to link against MPI even when not using it.
The HDF5 compiler wrapper calls the MPI compiler wrapper which would add that automatically but the CMake module does not follow this path. Read further for how I found that which might help for similar issues.
I found the solution by isolating the compiler commands invoked to the bare minimum. Using grep
I found references to MPI_*
already in the object file of the cpp source file. This eliminated the possibility of a relation to the libraries linked, so only differences in includes were possible. I compared the new and old HDF5 include directories with diff -qr
and found them to be the same.
Being sure it was the headers I examined the preprocessed files (g++ -E
). I compared the new vs old one with vimdiff
after some extra steps (replaced header include paths that changed from old to new system to keep the clutter to a minimum) Searching for mpi
I found the only difference to be the inclusion of mpi_cxx. This is done by mpi.h
which was also easily visible from the preprocessed output.
Checking the MPI installation on both systems confirmed, that new one was build with mpi_cxx support (C++ bindings for MPI added in MPI2 and removed in MPI3, but still optionally available as it seems) and the old one without.
As the C headers only have declarations no references land in the sources but the C++ bindings have definitions. This caused the references to land in the object file and later failed to resolve during linking.
Searching around all I found was "Parallel HDF5 IO requires MPI" but nothing related to CMake. https://www.hdfgroup.org/HDF5/release/cmakebuild.html is also pretty sparse about this and does not mention HDF5_IS_PARALLEL
(they do mention that they don't provide that find module).
Given that, I ended up adding an interface target, set the includes and libraries from hdf5, check for HDF_IS_PARALLEL
and add the mpi includes and libraries to that target.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…