You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A parallel HDF5 build with Fortran and the high-level Fortran library fails with an OpenMPI installation whose mpi.mod is located in CMake's MPI_Fortran_MODULE_DIR but not in MPI_Fortran_INCLUDE_DIRS.
The high-level Fortran targets add MPI_Fortran_INCLUDE_DIRS but omit MPI_Fortran_MODULE_DIR, so compilation fails because mpi.mod cannot be found.
The same configuration also copies MPI_C_LINK_FLAGS into global CMAKE_EXE_LINKER_FLAGS, despite already linking MPI::MPI_C. This applies C MPI-wrapper flags to Fortran linker invocations. In this environment, that propagates a raw -pthread flag to NAG Fortran, which does not accept it.
Expected behavior
A parallel HDF5 build with HDF5_BUILD_FORTRAN=ON and HDF5_BUILD_HL_LIB=ON should locate the MPI Fortran modules discovered by CMake and should not apply C-specific MPI wrapper linker flags globally to Fortran links.
Platform (please complete the following information)
HDF5 version: develop, commit 2888f82e837 (Add release page for 2.2.0)
OS and version: SLES 15 on NASA Discover
C compiler: GCC 12.3.0, via OpenMPI mpicc
Fortran compiler: NAG Fortran 7.2 build 7238, via OpenMPI mpif90
Build system: CMake 4.3.0, Ninja 1.12.0
MPI library: OpenMPI 4.1.6, built with GCC 12.3.0 and NAG Fortran 7.2.7238
CMake 4.3 currently has a separate issue with FortranCInterface_VERIFY() and NAG Fortran 7.2. A minimal reproducer has been reported to Kitware. I applied a temporary local guard for that unrelated CMake failure in order to complete this HDF5 build and isolate the issues described above.
With the proposed HDF5 changes and that temporary CMake workaround, HDF5 develop builds successfully in this configuration.
I didn't want to make a PR until you all thought it was a good idea.
AI assistance disclosure
GPT-5.6 Terra (Codex) assisted with diagnosing the build configuration and drafting the proposed changes. I independently built and verified the result.
@mathomp4 The change to CMAKE_EXE_LINKER_FLAGS looks reasonable to me; it seems that line has been there in one form or another since CMake support was added 16 years ago (ae06433), so very likely an outdated piece of logic by this point. As for the Fortran modules change, to me it would make sense to just add MPI_Fortran_MODULE_DIR to MPI_Fortran_INCLUDE_DIRS in the appropriate places to simplify things, but I'd be happy with the changes either way.
Activity
jhendersonHDF commentedon Jul 30, 2026
@mathomp4 The change to
CMAKE_EXE_LINKER_FLAGSlooks reasonable to me; it seems that line has been there in one form or another since CMake support was added 16 years ago (ae06433), so very likely an outdated piece of logic by this point. As for the Fortran modules change, to me it would make sense to just addMPI_Fortran_MODULE_DIRtoMPI_Fortran_INCLUDE_DIRSin the appropriate places to simplify things, but I'd be happy with the changes either way.