Compile with Intel oneAPI 2024 - errors at CMake configuration

I am trying to compile HDF5-1.14.6 with Intel 2024, but I still get issues with the ZLIB and libaec dependencies.
The idea would be to link them statically, so that I can link statically all the HDF5 dependency in my simulation code.

I am trying to compile with this configuration

cmake
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER=mpiicx -DCMAKE_CXX_COMPILER=mpiicpx -DCMAKE_Fortran_COMPILER=mpiifort
-DHDF5_ENABLE_PARALLEL=ON
-DCMAKE_INSTALL_PREFIX=~/hdf5-1.14.6-intel-parallel
-DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="GIT"
-DSZIP_USE_EXTERNAL=ON -DHDF5_USE_LIBAEC_STATIC=ON -DLIBAEC_GIT_URL:STRING="https://github.com/MathisRosenhauer/libaec" -DLIBAEC_GIT_BRANCH="v1.1.3"
-DZLIB_USE_EXTERNAL=ON -DHDF5_USE_ZLIB_STATIC=ON -DZLIB_GIT_URL:STRING="https://github.com/madler/zlib" -DZLIB_GIT_BRANCH="v1.3.1"
..

I was expecting that this configuration would allow parallel build with automatic download of the ZLIB and libaec dependencies.
Unfortunately, it seems that the CMake options are not working as expected, since I am getting these errors.

-- Renaming
--     [...]/hdf5/build/_deps/hdf5_zlib-src/zconf.h
-- to 'zconf.h.included' because this file is included with zlib
-- but CMake generates it automatically in the build directory.
CMake Error at config/cmake/HDFLibMacros.cmake:40 (add_library):
  add_library cannot create ALIAS target "zlib-static" because another target
  with the same name already exists.
Call Stack (most recent call first):
  CMakeFilters.cmake:140 (EXTERNAL_ZLIB_LIBRARY)
  CMakeLists.txt:921 (include)


CMake Warning at CMakeFilters.cmake:163 (message):
   ZLib support in HDF5 was enabled but not found
Call Stack (most recent call first):
  CMakeLists.txt:921 (include)


-- Performing Test HAVE_DECL___BUILTIN_CLZLL
-- Performing Test HAVE_DECL___BUILTIN_CLZLL - Success
-- Looking for snprintf
-- Looking for snprintf - found
-- Final: share
CMake Error at config/cmake/HDFLibMacros.cmake:78 (add_library):
  add_library cannot create ALIAS target "szaec-static" because another
  target with the same name already exists.
Call Stack (most recent call first):
  CMakeFilters.cmake:200 (EXTERNAL_SZIP_LIBRARY)
  CMakeLists.txt:921 (include)


CMake Warning at CMakeFilters.cmake:221 (message):
  SZIP support in HDF5 was enabled but not found
Call Stack (most recent call first):
  CMakeLists.txt:921 (include)

Do you have any suggestion on how to fix? Are there any correction to be made on th CMake configuration and/or definition?

Thank you!

Yes, the options seem to be correct - I have not tried with parallel/intel. Do the options work without parallel enabled? I would double check that first - because we do have workflows that do test that configuration.
The parallel and compression are tested in the “cmake-par-source.yml” workflow file, which means that it should work.

Make sure the following are correctly set:
-DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON
-DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON
-DHDF5_ENABLE_SZIP_ENCODING:BOOL=ON
-DZLIB_USE_LOCALCONTENT:BOOL=OFF
-DLIBAEC_USE_LOCALCONTENT:BOOL=OFF

My understanding of the cmake-par-source.yml is that it employs the libaec-dev package available as pre-built binary in Ubuntu.
This is fundamentally different with respect of the compilation from source of that dependency, however.

I get precisely the same errors with the additional options suggested, either with or without parallel build request. :frowning:

Yes, it has been awhile since I investigated these options. I always use the cacheinit.cmake file.
I was wrong about USE_LOCALCONTENT - should be ON

I have used presets to build parallel (just change the appropriate settings as needed):
Create a CMakeUserPresets.json file with the following content:
\code
{
“version”: 6,
“cmakeMinimumRequired”: {
“major”: 3,
“minor”: 24,
“patch”: 0
},
“configurePresets”: [
{
“name”: “my-linux-par”,
“hidden”: true,
“description”: “Build HDF5 with library and tools using parallel compiler”,
“inherits”: [“ci-base”, “ci-CompressionVars”, “ci-StdExamples”],
“environment”: {
“CC”: “mpicc”
},
“cacheVariables”: {
“HDF_PACKAGE_NAMESPACE”: {“type”: “STRING”, “value”: “hdf5::”},
“HDF5_BUILD_SHARED_LIBS”: “ON”,
“HDF5_BUILD_TOOLS”: “ON”,
“MPIEXEC_NUMPROC_FLAG”: “-n”,
“MPIEXEC_MAX_NUMPROCS”: “2”,
“HDF5_ENABLE_PARALLEL”: “ON”,
“HDF5_ENABLE_SUBFILING_VFD”: “OFF”,
“HDF5_ENABLE_ZLIB_SUPPORT”: “ON”,
“HDF5_ENABLE_LIBAEC”: “ON”,
“HDF5_ENABLE_PLUGIN_SUPPORT”: “OFF”
}
},
{
“name”: “my-linux-par-mpich”,
“description”: “mpich Standard Config for x64 (Release)”,
“inherits”: [
“ci-x64-Release-GNUC”,
“my-linux-par”
]
}
],
“buildPresets”: [
{
“name”: “my-linux-par-mpich”,
“description”: “mpich Standard Build for x64 (Release)”,
“configurePreset”: “my-linux-par-mpich”,
“inherits”: [
“ci-x64-Release-GNUC”
]
}
],
“testPresets”: [
{
“name”: “my-linux-serial-mpich”,
“configurePreset”: “my-linux-par-mpich”,
“inherits”: [
“ci-x64-Release-GNUC”
],
“filter”: {
“exclude”: {
“name”: “MPI_TEST”
}
}
},
{
“name”: “my-linux-par-mpich”,
“configurePreset”: “my-linux-par-mpich”,
“inherits”: [
“ci-x64-Release-GNUC”
],
“filter”: {
“include”: {
“name”: “MPI_TEST”
}
}
}
],
“packagePresets”: [
{
“name”: “my-linux-par-mpich”,
“configurePreset”: “my-linux-par-mpich”,
“inherits”: “ci-x64-Release-GNUC”
}
],
“workflowPresets”: [
{
“name”: “my-linux-par-mpich”,
“steps”: [
{“type”: “configure”, “name”: “my-linux-par-mpich”},
{“type”: “build”, “name”: “my-linux-par-mpich”},
{“type”: “test”, “name”: “my-linux-serial-mpich”},
{“type”: “test”, “name”: “my-linux-par-mpich”},
{“type”: “package”, “name”: “my-linux-par-mpich”}
]
}
]
}
\endcode

Unfortunately it does not work, neither with Intel compiler nor with GCC.
Intestingly enough, if configuring with dynamic linking, it does not work with CMake, but it works with autoconf.
Apparently the CMake files seems having some bugs.
Is there a way to request static linking of zlib and libaec with autoconf?

Hi, @alberto.previti!

Please try the following steps:

  1. Use fork: GitHub - hyoklee/hdf5: Unofficial HDF5® Library Repository
  2. Run CMake: actions/.github/workflows/lin-icx-sh-f-p-h-sz.yml at main · hyoklee/actions · GitHub
  3. Verify Result: CDash

Note: I tested Intel oneAPI 2025.1 / Ubuntu-24.04.

See Also: Building (intel) HDF5 1.14.6 with zlib and szip - #21 by hyoklee

Basically the last method suggested employs the libaec compiled as a system package with gcc, which is indeed different with respect to the compilation of a dedicated libaec with Intel oneAPI.
Apparently, the embedded procedure to download and compile zlib and libaec is not working as expected.

As a workaround, it is possible to specify the libaec_ROOT and ZLIB_ROOT variables, that work fine. In this sense, the original problem should be considered as solved.
Anyhow, the current CMake scripts does not set the runpath for these dependencies, so that the resulting HDF5 binaries will still look at system zlib and libaec instead of the custom ones.
I would suggest to let CMake add the relevant paths to runpath, so that this problem is avoided.

By looking at the current development branch on GitHub, it seems that a very significant amount of changes have been done since last stable release. This is the reason why I have not (yet) proposed a pull request for the runpath issue, but, if needed, I may look at it.

Hi, @alberto.previti!

How about using vpkg if you really need oneAPI-compiled szip/zlib?

Workflow: actions/.github/workflows/lin-vcpkg-icx-sz-zl.yml at main · hyoklee/actions
Action: ci(lin,vcpkg,icx): test · hyoklee/actions@81fde60

Note: hdf5 vcpkg builds zlib/szip by default.

Since in any case HDF5 applications often requires dedicated settings, I normally prefer to statically link this library and, for consistency, to employ the same compiler for all dependencies.

In order to let it work, I see that the following configuration works fine.

cmake -G Ninja
-DCMAKE_INSTALL_PREFIX=/opt/hdf5-v1.14.6-intel-mpi
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DCMAKE_C_COMPILER=/opt/intel/oneapi/2024.2.1/mpi/2021.13/bin/mpiicx
-DCMAKE_CXX_COMPILER=/opt/intel/oneapi/2024.2.1/mpi/2021.13/bin/mpiicpx
-DCMAKE_Fortran_COMPILER=/opt/intel/oneapi/2024.2.1/mpi/2021.13/bin/mpiifort
-DZLIB_ROOT=/opt/zlib-v1.3.1-intel
-Dlibaec_ROOT=/opt/libaec-v1.1.3-intel
-DHDF5_ENABLE_PARALLEL=ON
..

In addition, to correctly set the RUNPATH so that the provided zlib and libaec are found, the following patch may be considered.

diff --git a/config/cmake/HDFMacros.cmake b/config/cmake/HDFMacros.cmake
index 3be3e6a6a6..12a1d2eaa4 100644
--- a/config/cmake/HDFMacros.cmake
+++ b/config/cmake/HDFMacros.cmake
@@ -460,12 +460,11 @@ macro (HDF_DIR_PATHS package_prefix)

   # Always use full RPATH, i.e. don't skip the full RPATH for the build tree
   set (CMAKE_SKIP_BUILD_RPATH  OFF)
+
   # when building, don't use the install RPATH already
   # (but later on when installing)
-  set (CMAKE_INSTALL_RPATH_USE_LINK_PATH  OFF)
-  # add the automatically determined parts of the RPATH
-  # which point to directories outside the build tree to the install RPATH
-  set (CMAKE_BUILD_WITH_INSTALL_RPATH ON)
+  set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
+
   if (APPLE)
     set (CMAKE_INSTALL_NAME_DIR "@rpath")
     set (CMAKE_INSTALL_RPATH
@@ -475,9 +474,13 @@ macro (HDF_DIR_PATHS package_prefix)
         "@loader_path/"
     )
   else ()
-    set (CMAKE_INSTALL_RPATH "\$ORIGIN/../${${package_prefix}_INSTALL_LIB_DIR}:\$ORIGIN/")
+    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
   endif ()

+  # add the automatically determined parts of the RPATH
+  # which point to directories outside the build tree to the install RPATH
+  set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
+
   if (DEFINED ADDITIONAL_CMAKE_PREFIX_PATH AND EXISTS "${ADDITIONAL_CMAKE_PREFIX_PATH}")
     set (CMAKE_PREFIX_PATH ${ADDITIONAL_CMAKE_PREFIX_PATH} ${CMAKE_PREFIX_PATH})
   endif ()
1 Like