Building (intel) HDF5 1.14.6 with zlib and szip

Greetings,

I’ve been trying to compile pHFD5 with szip and zlib support for awhile now to no avail. I’ve tried to build from

1) Precompiled system libs

cmake -G "Unix Makefiles" --log-level=VERBOSE --fresh \
                -DBUILD_SHARED_LIBS:BOOL=ON \
                -DHDF5_ENABLE_PARALLEL:BOOL=ON \
                -DCMAKE_C_COMPILER=`which mpicc` -DCMAKE_CXX_COMPILER=`which mpicxx` -DCMAKE_Fortran_COMPILER=`which mpifort` \
                -DHDF5_PACKAGE_EXTLIBS:BOOL=ON \
                -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON \
                -DZLIB_USE_EXTERNAL:BOOL=OFF -DZLIB_LIBRARY:PATH="/usr/lib64/libz.so.1" -DZLIB_INCLUDE_DIR="/usr/include" \
                -DSZIP_USE_EXTERNAL:BOOL=OFF -DSZIP_LIBRARY:PATH="/usr/lib64/libsz.so.2.0.1" -DSZIP_INCLUDE_DIR="/usr/include" \
                ..

2) tar.gz source files

cmake -G "Unix Makefiles" --log-level=VERBOSE --fresh \
                -DBUILD_SHARED_LIBS:BOOL=ON \
                -DHDF5_ENABLE_PARALLEL:BOOL=ON \
                -DCMAKE_C_COMPILER=`which mpicc` -DCMAKE_CXX_COMPILER=`which mpicxx` -DCMAKE_Fortran_COMPILER=`which mpifort` \
                -DHDF5_PACKAGE_EXTLIBS:BOOL=ON \
                -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON \
                -DHDF5_EXTERNALLY_CONFIGURED=ON -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ" \
                -DZLIB_USE_EXTERNAL:BOOL=OFF -DSZIP_USE_EXTERNAL:BOOL=OFF -DLIBAEC_USE_EXTERNAL:BOOL=OFF \
                -DZLIB_USE_LOCALCONTENT:BOOL=ON -DSZIP_USE_LOCALCONTENT:BOOL=ON -DLIBAEC_USE_LOCALCONTENT:BOOL=ON \
                -DTGZPATH:PATH=`realpath ../` -DZLIB_TGZ_NAME:STRING="zlib-1.3.1.tar.gz" -DSZIP_TGZ_NAME:STRING="szip-2.1.1.tar.gz" -DLIBAEC_TGZ_NAME:STRING="libaec-v1.1.3.tar.gz" \
                ..
## 3) Scratch-built `zlib`/`szip`
        ```cmake -G "Unix Makefiles" --log-level=VERBOSE --fresh \
                -DBUILD_SHARED_LIBS:BOOL=ON \
                -DHDF5_ENABLE_PARALLEL:BOOL=ON \
                -DCMAKE_C_COMPILER=`which mpicc` -DCMAKE_CXX_COMPILER=`which mpicxx` -DCMAKE_Fortran_COMPILER=`which mpifort` \
                -DHDF5_PACKAGE_EXTLIBS:BOOL=ON \
                -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON \
                -DZLIB_ROOT=`realpath ../zlib-1.3.1/zlib` \
                -DZLIB_LIBRARY=`realpath ../zlib-1.3.1/zlib/lib/libz.so` \
                -DZLIB_INCLUDE_DIR=`realpath ../zlib-1.3.1/zlib/include` \
                -DSZIP_ROOT=`realpath ../szip-2.1.1/szip` \
                -DSZIP_LIBRARY=`realpath ../szip-2.1.1/szip/lib/libsz.so` \
                -DSZIP_INCLUDE_DIR=`realpath ../szip-2.1.1/szip/include` \
                -DLIBAEC_ROOT=`realpath ../libaec-v1.1.3/libaec` \
                -DLIBAEC_LIBRARY=`realpath ../libaec-v1.1.3/libaec/lib64/libaec.so` \
                -DLIBAEC_INCLUDE_DIR=`realpath ../libaec-v1.1.3/libaec/include` \
                -DCMAKE_PREFIX_PATH="$(realpath ../zlib-1.3.1/zlib);$(realpath ../szip-2.1.1/szip);$(realpath ../libaec-v1.1.3/libaec)" \
                ..

(All followed by cmake --build . --clean-first -j$(nproc) --config Release -v)

Now some appear to have built successfully but pHDF5 for me is just a dependency for another application. When I try to compile this other application, it reports
CMake Error at /path/to/hdf5/cmake/hdf5-config.cmake: include could not find requested file: /path/to/hdf5/cmake/zlib-targets.cmake. Which, to me, seems like zlib isn’t actually building. Am I understanding correctly? Why isn’t this file present (am I missing a flag)?

Build logs for each attached
scratch-built.log (2.2 MB)
targz-built.log (24.8 KB)
systemlib-built.log (3.0 MB)

Not answering question, but libaec is the open replacement for szip - using both could cause issues.
In INSTALL_CMake.txt file there are multiple ways to build HDF5 with various methods of zlib/libaec. Also check the config/cmake/cacheinit.cmake file for hints - it is the file we use to build binaries. (I prefere the tgz method, and there are examples in our CI workflows).

Allen

Hi, @sterlingbutters !

Would you please attach the build error logs?
What is your OS (e.g., uname -a output)?

@byrn when I tried to install with szip only the log kept reporting that libaec was missing so I figured I’d just give it both and see what happened. How can I have cmake ignore one or the other and which would you recommend?

Also thank you for pointing out INSTALL_CMake.txt, that is super helpful - I’ve been enumerating flags by searching forum posts and knew there had to be a better way.

@hyoklee Sorry, they were already uploaded but the markdown formatting was wrong and I couldn’t initially edit the post once I created it (it’s fixed now)

also: Linux <hostname>.com 4.18.0-553.5.1.el8_10.x86_64 #1 SMP Tue May 21 03:13:04 EDT 2024 x86_64 x86_64 x86_64 GNU/Linux

1 Like

@byrn @hyoklee Interestingly I found this in hdf5-config.cmake:

#-----------------------------------------------------------------------------
# Don't include targets if this file is being picked up by another
# project which has already built hdf5 as a subproject
#-----------------------------------------------------------------------------
if (NOT TARGET "hdf5")
  if (${HDF5_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT AND ${HDF5_PACKAGE_NAME}_PACKAGE_EXTLIBS)
    include (${PACKAGE_PREFIX_DIR}/cmake/zlib-targets.cmake)
  endif ()
  if (${HDF5_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT AND ${HDF5_PACKAGE_NAME}_PACKAGE_EXTLIBS)
    include (${PACKAGE_PREFIX_DIR}/cmake/libaec-targets.cmake)
  endif ()
  include (${PACKAGE_PREFIX_DIR}/cmake/hdf5-targets.cmake)
endif ()

But I’m not sure how to interpret it exactly. Since I’m currently compiling HDF5 not via a some subproject, shouldn’t these targets be being built?

This is all I get currently:

-- Installing: /home/n06174/software/hdf5-1.14.6/hdf5/cmake/hdf5-targets.cmake
-- Installing: /home/n06174/software/hdf5-1.14.6/hdf5/cmake/hdf5-targets-noconfig.cmake
-- Installing: /home/n06174/software/hdf5-1.14.6/hdf5/cmake/hdf5-config.cmake
-- Installing: /home/n06174/software/hdf5-1.14.6/hdf5/cmake/hdf5-config-version.cmake

That comment is refering to this check - if the target is not hdf5 then skip. In your case it is not skipped.

@byrn Right so shouldn’t the targets be built? I guess that’s why I’m confused how/why cmake finds libaec and zlib but doesn’t generate the targets:

-- Filter ZLIB file is /
-- Filter SZIP file is /
-- Filter HDF5_ZLIB package name:zlib
-- Found ZLIB: /home/n06174/software/hdf5-1.14.6/zlib-1.3.1/zlib/lib/libz.so.1.3.1 (found version "1.3.1")  
-- Filter HDF5_ZLIB is ON
-- H5_ZLIB_HEADER=zlib.h
-- Found libaec: /home/n06174/software/hdf5-1.14.6/libaec-v1.1.3/libaec/cmake/libaec-config.cmake (found version "1.1.3")
-- H5_SZIP_FOUND=TRUE and LINK_COMP_LIBS=ZLIB::ZLIB;libaec::sz;libaec::aec
-- LINK_COMP_LIBS=ZLIB::ZLIB;libaec::sz;libaec::aec
-- Filter SZIP is ON
-- H5_ZLIB_HEADER for library=zlib.h
-- H5_ZLIB_HEADER=zlib.h
-- H5_ZLIB_HEADER for direct_chunk=zlib.h
-- H5_ZLIB_HEADER for zip_perf=zlib.h
-- HDF5 Example H5EX_RESOURCES_DIR: /home/n06174/software/hdf5-1.14.6/config/cmake
-- HDF5 H5_LIBVER_DIR: 114 HDF5_API_VERSION: v114
-- HDF5 Example link libs: hdf5-shared;hdf5_hl-shared Includes: /home/n06174/software/hdf5-1.14.6/src;/home/n06174/software/hdf5-1.14.6/src/H5FDsubfiling;/home/n06174/software/hdf5-1.14.6/build/src;/home/n06174/software/hdf5-1.14.6/hl/src;/home/n06174/software/hdf5-1.14.6/build/hl/src
-- HDF5 link libs: hdf5-shared;hdf5_hl-shared

@byrn @hyoklee I think my issue is related to or the same as: CMake: zlib dependency not properly propagted by hdf5 targets - HDF5 Library - HDF Forum

If you are finding the libs instead of building them in-line then there will be no files created or packaged.

@byrn Why is that? That doesn’t make a whole lot of sense to me (I thought that was the point of HDF5_PACKAGE_EXTLIBS). If an external project wants to reference HDF5 instance then how can it do that without building those targets?

Ok so if I build inline, this is what happens:

        cmake .. -G "Unix Makefiles" --log-level=VERBOSE --fresh \
                -DBUILD_SHARED_LIBS:BOOL=ON \
                -DHDF5_ENABLE_PARALLEL:BOOL=ON \
                -DCMAKE_C_COMPILER=`which mpicc` -DCMAKE_CXX_COMPILER=`which mpicxx` -DCMAKE_Fortran_COMPILER=`which mpifort` \
                -DHDF5_PACKAGE_EXTLIBS:BOOL=ON \
                -DCMAKE_INSTALL_PREFIX:PATH=`realpath ../hdf5` \
                -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=ON -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON \
                -DHDF5_EXTERNALLY_CONFIGURED=ON -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING="TGZ" \
                -DZLIB_USE_EXTERNAL:BOOL=ON -DSZIP_USE_EXTERNAL:BOOL=ON -DLIBAEC_USE_EXTERNAL:BOOL=ON \
                -DZLIB_USE_LOCALCONTENT:BOOL=ON -DSZIP_USE_LOCALCONTENT:BOOL=ON -DLIBAEC_USE_LOCALCONTENT:BOOL=ON \
                -DTGZPATH:PATH=`realpath ../` -DZLIB_TGZ_NAME:STRING="zlib-1.3.1.tar.gz" -DLIBAEC_TGZ_NAME:STRING="libaec-v1.1.3.tar.gz"
-- Filter ZLIB file is /home/n06174/software/hdf5-1.14.6/zlib-1.3.1.tar.gz
-- Filter SZIP file is /home/n06174/software/hdf5-1.14.6/libaec-v1.1.3.tar.gz
-- Filter ZLIB file /home/n06174/software/hdf5-1.14.6/zlib-1.3.1.tar.gz
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Final: share
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)


-- Filter HDF5_ZLIB is built
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)


-- H5_ZLIB_HEADER=
-- Filter SZIP file /home/n06174/software/hdf5-1.14.6/libaec-v1.1.3.tar.gz
-- 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)


-- Filter SZIP is built using library AEC
-- LINK_COMP_LIBS=
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)


CMake Error at utils/subfiling_vfd/CMakeLists.txt:8 (file):
  file COPY given no DESTINATION


-- HDF5 Example H5EX_RESOURCES_DIR: /home/n06174/software/hdf5-1.14.6/config/cmake
-- HDF5 H5_LIBVER_DIR: 114 HDF5_API_VERSION: v114
-- HDF5 Example link libs: hdf5-shared;hdf5_hl-shared Includes: /home/n06174/software/hdf5-1.14.6/src;/home/n06174/software/hdf5-1.14.6/src/H5FDsubfiling;/home/n06174/software/hdf5-1.14.6/build/src;/home/n06174/software/hdf5-1.14.6/hl/src;/home/n06174/software/hdf5-1.14.6/build/hl/src
-- HDF5 link libs: hdf5-shared;hdf5_hl-shared
-- HDF5 H5_LIBVER_DIR: 114 HDF5_VERSION_MAJOR: 1.14
-- Configuring incomplete, errors occurred!

Because it does not always have the details that are available when building it in-line. So we can’t create extra info needed for packaging other than creating a dependency.

As far as the configure error - I don’t know why because the options look correct. The target names should not be used anywhere else. I can only suggest maybe inspecting the CI workflows for some clues.

@byrn

Well this double print is certainly fishy to me for zlib (however thats not very insightful for the same failure that szip endures).

What exactly do you mean by CI workflows? Is there any other information I can provide that would help in debugging? I’m afraid I’m not actually very good with CMake.

@byrn

Here are the contents of config/cmake/HDFLibMacros.cmake in case it is of interest:

#-------------------------------------------------------------------------------
macro (EXTERNAL_ZLIB_LIBRARY compress_type)
  if (HDF5_USE_ZLIB_NG)
    set (zlib_folder "ZLIBNG")
  else ()
    set (zlib_folder "ZLIB")
  endif ()
  if (${compress_type} MATCHES "GIT")
    FetchContent_Declare (HDF5_ZLIB
        GIT_REPOSITORY ${ZLIB_URL}
        GIT_TAG ${ZLIB_BRANCH}
        PATCH_COMMAND ${CMAKE_COMMAND} -E copy
            ${HDF_RESOURCES_DIR}/${zlib_folder}/CMakeLists.txt
            <SOURCE_DIR>/CMakeLists.txt
    )
  elseif (${compress_type} MATCHES "TGZ")
    message (VERBOSE "Filter ZLIB file ${ZLIB_URL}")
    FetchContent_Declare (HDF5_ZLIB
        URL ${ZLIB_URL}
        URL_HASH ""
        PATCH_COMMAND ${CMAKE_COMMAND} -E copy
            ${HDF_RESOURCES_DIR}/${zlib_folder}/CMakeLists.txt
            <SOURCE_DIR>/CMakeLists.txt
    )
  endif ()

  FetchContent_MakeAvailable(HDF5_ZLIB)

  add_library(${HDF_PACKAGE_NAMESPACE}zlib-static ALIAS zlib-static)
  set (H5_ZLIB_STATIC_LIBRARY "${HDF_PACKAGE_NAMESPACE}zlib-static")
  set (H5_ZLIB_LIBRARIES ${H5_ZLIB_STATIC_LIBRARY})
  if (HDF5_USE_ZLIB_NG)
    set (H5_ZLIB_HEADER "zlib-ng.h")
  else ()
    set (H5_ZLIB_HEADER "zlib.h")
  endif ()

  set (H5_ZLIB_INCLUDE_DIR_GEN "${hdf5_zlib_BINARY_DIR}")
  set (H5_ZLIB_INCLUDE_DIR "${hdf5_zlib_SOURCE_DIR}")
  set (H5_ZLIB_FOUND 1)
  set (H5_ZLIB_INCLUDE_DIRS ${H5_ZLIB_INCLUDE_DIR_GEN} ${H5_ZLIB_INCLUDE_DIR})
endmacro ()

#-------------------------------------------------------------------------------
macro (EXTERNAL_SZIP_LIBRARY compress_type encoding)
  # Only libaec library is usable
  if (${compress_type} MATCHES "GIT")
    FetchContent_Declare (SZIP
        GIT_REPOSITORY ${SZIP_URL}
        GIT_TAG ${SZIP_BRANCH}
        PATCH_COMMAND ${CMAKE_COMMAND} -E copy
            ${HDF_RESOURCES_DIR}/LIBAEC/CMakeLists.txt
            <SOURCE_DIR>/CMakeLists.txt
    )
  elseif (${compress_type} MATCHES "TGZ")
    message (VERBOSE "Filter SZIP file ${SZIP_URL}")
    FetchContent_Declare (SZIP
        URL ${SZIP_URL}
        URL_HASH ""
        PATCH_COMMAND ${CMAKE_COMMAND} -E copy
            ${HDF_RESOURCES_DIR}/LIBAEC/CMakeLists.txt
            <SOURCE_DIR>/CMakeLists.txt
    )
  endif ()
  FetchContent_MakeAvailable(SZIP)

  add_library (${HDF_PACKAGE_NAMESPACE}szaec-static ALIAS szaec-static)
  add_library (${HDF_PACKAGE_NAMESPACE}aec-static ALIAS aec-static)
  set (H5_SZIP_STATIC_LIBRARY "${HDF_PACKAGE_NAMESPACE}szaec-static;${HDF_PACKAGE_NAMESPACE}aec-static")
  set (H5_SZIP_LIBRARIES ${H5_SZIP_STATIC_LIBRARY})

  set (H5_SZIP_INCLUDE_DIR_GEN "${szip_BINARY_DIR}")
  set (H5_SZIP_INCLUDE_DIR "${szip_SOURCE_DIR}/include")
  set (H5_SZIP_FOUND 1)
  set (H5_SZIP_INCLUDE_DIRS ${H5_SZIP_INCLUDE_DIR_GEN} ${H5_SZIP_INCLUDE_DIR})
endmacro ()

@byrn @hyoklee

I would say my issue is similar to Building with zlib (and szip) on windows - HDF5 Library / C++ Users’ Group - HDF Forum but they just worked around the error by building szip and zlib from scratch which doesn’t work for me since I need zlib-targets.cmake. Any other workarounds you can think of?

So I had much more luck just avoiding cmake altogether and building with regular make:

        ../configure CC=`which $CC` CXX=`which $CXX` FC=`which $FC` \
                    CFLAGS='-diag-disable=10441' CXXFLAGS='-diag-disable=10441' FCFLAGS='-diag-disable=10441' \
                     --enable-parallel --enable-fortran \
                     --with-zlib=`realpath ../zlib-1.3.1/zlib` --with-szlib=`realpath ../szip-2.1.1/szip`  --prefix=`realpath ../hdf5` && \

                make all -j1 && \
                make install

Admittedly, its still not clear to how to point configure to libaec instead of szip (since configure reported that it could not find libaec when I just drop-in replaced the root dir for the libaec instance against the szip flag. Not even sure if I need szip anyway and at least I have still have zlib.

The double print is actually slightly different - the first shows the setting the second shows what was used.

In the hdf5 repo .github/workflows folder has CI files that test hdf5 on different platforms and compilers.

For CMake (no parallel and build compression libs inline) you could just try using:
“cmake --workflow --preset ci-StdShar-gcc --fresh”
This would give you a starting point to create a CMakeUsers.json file to customize. (See the develop doxygen for the Presets Cookbook)