Install netCDF-c with HDF5
Hello,
I have installed HDF5-1.12.0 with CMake using the following command:
cmake -DCMAKE_INSTALL_PREFIX=/public/home/hdf5 -DBUILD_SHARED_LIBS=OFF -DHDF5_BUILD_FORTRAN=ON -DHDF5_ENABLE_PARALLEL=ON -DHDF5_BUILD_CPP_LIB=OFF - DHDF5_BUILD_HL_LIB=ON -DHDF5_ENABLE_Z_LIB_SUPPORT=ON -DZLIB_ROOT=/public/home/zlib -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_ROOT=/public/home/szip - DCMAKE_BUILD_TYPE=RELEASE .. 2>&1 | tee log.cmake
and then install netCDF-c-4.8.0 with the following command:
cmake -DCMAKE_INSTALL_PREFIX=/public/home/netcdf -DZLIB_ROOT=/public/home/zlib -DSZIP_ROOT=/public/home/szip - DHDF5_ROOT=/public/home/hdf5 -DCURL_ROOT=/public/home/curl -DCMAKE_BUILD_TYPE=RELEASE .. 2>&1 | tee log.cmake
but it failed with an error:
CMake Error at CMakeLists.txt:794 (MESSAGE): hdf5 does not contain symbol '_H5Literate'. Please recompile your libhdf5 install using '--with-default-api-version=v18'.
However, I have tried to reinstall HDF5 added -DDEFAULT_API_VERSION=V18 and reinstall netCDF-C, the error still occurred.
Again, I used configure to reinstall netCDF-c:
export CPPFLAGS=-DH5_USE_110_API
CPPFLAGS="-I/public/home/zlib/include -I/public/home/szip/include -I/public/home/hdf5/include -I/public/home/curl/include" LDFLAGS="-L/public/home/zlib/lib -L/public/home/szip/lib -L/public/home/hdf5/lib -L/public/home/curl/lib" ./configure --prefix=/public/home/netcdf
and a new error occurred:
configure: error: Can't find or link to the hdf5 library. Use --disable-hdf5, or see config.log for errors.
How can I fix these problem, and how to use CMake to install netCDF-c correctly.
Thanks a lot!
Jepaung
Try CPPFLAGS=-DH5_USE_110_API cmake
It still seems to have the same effect with the following error:
[hihope-rzg2n-devkit]:~/netcdf-c-4.8.0/build> CPPFLAGS=-DH5_USE_110_API cmake .. -- Found HDF5 libraries version 1.12.0 -- Using HDF5 include dir: /opt/hihope/2.4.3/sysroots/aarch64-niic-linux/usr/include CMake Error at CMakeLists.txt:794 (MESSAGE): /opt/hihope/2.4.3/sysroots/aarch64-niic-linux/usr/lib64/libhdf5.so.200.0.0 does not contain symbol '_H5Literate'. Please recompile your libhdf5 install using '--with-default-api-version=v18'.
-- Configuring incomplete, errors occurred! See also "/home/blithe/netcdf-c-4.8.0/build/CMakeFiles/CMakeOutput.log". See also "/home/blithe/netcdf-c-4.8.0/build/CMakeFiles/CMakeError.log".
Can you try again with current main branch and see if this problem still exists?
I had a comment above here saying I had the same problem, but I was incorrect. Leaving here the following in case it helps others:-
The issue seems to be in HDF5, not NetCDF. The CMake scripts of HDF5 do not pick up -DDEFAULT_API_VERSION="v18", or at least it is not propagated correctly. Running the "old fashioned" way with ./configure --with-default-api-version=v18 [...] and make && make install gets the proper symbols exported and detected by NetCDF.
Thank you @icvisser. The combinatorics of possible options here between HDF5 and NetCDF are vast, we have tried to capture the bulk of common use cases for modern versions; you'll find that for HDF5 1.14.x and NetCDF 4.9.2+, you will need to revert the DEFAULT_API_VERSION; I'm not sure if it will break it or is simply unnecessary, but it is something to bear in mind.