I’m using essentially the same script for hdf5 version 1.14 and 2.whatever. But netcdf is happy with 1.14 and not with 2:
-- Found HDF5: hdf5-shared (found version "2.0.0") found components: C HL
-- Found HDF5 version: 2.0.0
-- Using HDF5 include dir: /scratch/00434/eijkhout/installation/installation-hdf5-2.0.0-stampede3-gcc15.1/include
-- Found Threads: TRUE
-- Checking for HDF5 config header
-- Looking for H5public.h
-- Looking for H5public.h - found
-- Using H5public.h to check for feature macros
-- Checking for H5_HAVE_ZLIB_H
-- Performing Test _has_H5_HAVE_ZLIB_H
-- Performing Test _has_H5_HAVE_ZLIB_H - Failed
CMake Error at cmake/dependencies.cmake:161 (message):
HDF5 was built without zlib. Rebuild HDF5 with zlib.
I can not find the instructions on how to specify zlib for cmake. I’m using:
For HDF5 2.0.0, the CMake option was renamed from HDF5_ENABLE_Z_LIB_SUPPORT to HDF5_ENABLE_ZLIB_SUPPORT to be consistent with other options. If you’re using a zlib that is already installed on your system, passing just -DHDF5_ENABLE_ZLIB_SUPPORT=ON should be enough to find that zlib. If the zlib is installed to a non-system directory, you may also have to pass the option -DZLIB_ROOT=${prefix}, where ${prefix} is the top-level directory of where zlib is installed to.
-D HDF5_ENABLE_ZLIB_SUPPORT:BOOL=ON
-D ZLIB_USE_EXTERNAL=ON
-D ZLIB_ROOT=/scratch/00434/eijkhout/installation/installation-zlib-1.3.2-stampede3-gcc15.1.0
-D ZLIB_INCLUDE_DIR:PATH=/scratch/00434/eijkhout/installation/installation-zlib-1.3.2-stampede3-gcc15.1.0/include
-D ZLIB_LIBRARY:PATH=/scratch/00434/eijkhout/installation/installation-zlib-1.3.2-stampede3-gcc15.1.0/lib64/libz.so
result:
ZLib support in HDF5 was enabled but not found
“If the zlib is installed to a non-system directory,” What is a system directory? Note that zlib supports both pkg-config & cmake modules and I have specified the paths to both. I see that you have lines "find_package( ZLIB " so I was expecting you to use cmake modules. No?
Yes, HDF5 relies on CMake’s module to locate zlib. In this case, a system directory would be any of the default directories CMake searches for zlib-related CMake files, which would generally be those listed at find_package — CMake 4.4.0 Documentation. Since you have CMAKE_PREFIX_PATH set to include your zlib installation directory, I’d expect that you shouldn’t need to pass any options other than -DHDF5_ENABLE_ZLIB_SUPPORT=ON. ZLIB_USE_EXTERNAL should not be specified, as that option is used to have the HDF5 build process also build zlib from source. ZLIB_INCLUDE_DIR and ZLIB_LIBRARY also usually don’t need to be set and in some cases doing so will cause issues with CMake being able to properly find zlib.
If specifying just -DHDF5_ENABLE_ZLIB_SUPPORT=ON is not enough for CMake to locate the zlib installation, it may be useful to pass the --debug-find option to the cmake command to help figure out why it isn’t being located.
I can’t guarantee this is the only problem, but according to hdf5/docs/INSTALL_CMake_options.md at develop · HDFGroup/hdf5 · GitHub , ZLIB_USE_EXTERNAL defaults to OFF, and the description for the option is “If ON, specifies that zlib libraries should be retrieved from an external source and should be built while building HDF5.” To me that option is poorly named because it seems that it would be ON for ZLIB not installed as part of the HDF5 build, but instead ON indicates merely that zlib should be built along with HDF5 using externally acquired source which also requires adding options for downloading the source. I suggest removing “-D ZLIB_USE_EXTERNAL=ON” or setting it to OFF.
Amazing. Removing the EXTERNAL option did the trick.
Hdf5 reports:
-- Found ZLIB: /scratch/00434/eijkhout/installation/installation-zlib-1.3.2-stampede3-gcc15.1.0/lib64/libz.so (found version “1.3.2”)
– H5_ZLIB_HEADER=zlib.h
so it is using my zlib.
Now netcdf says:
-- Checking for H5_HAVE_ZLIB_H
– Performing Test _has_H5_HAVE_ZLIB_H
– Performing Test _has_H5_HAVE_ZLIB_H - Success
– Found ZLIB: /usr/lib64/libz.so (found version “1.2.11”)
which is almost correct: it seems to find zlib in h5, but then does not use mine. However, that is probably an issue for netcdf, not for you.