Using HDF5 Libraries with CMake on Windows (Error:

2019-08-03 07:05发布

I want to use the HDF5 libraries in my C++ program. I am using the VS 2010 x64 compiler and CMake 3.8.0rc2 on Windows 7. The HDF5 version I installed is 1.8.10 (installed by running the official "Installer").

In my CMakeLists file, I added the following lines:

FIND_PACKAGE ( HDF5 REQUIRED )
INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIRS})
SET (HDF5_LIBS ${HDF5_LIBS} ${HDF5_LIBRARIES})
...
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${HDF5_LIBS})

CMake shows the following error message upon Configuring:

Could NOT find HDF5 (missing: HDF5_LIBRARIES)

I also added the environment variables HDF5_DIR and HDF5_ROOT which both point to my HDF5 installation folder C:\Develop\HDF5\1.8.10.

What am I missing to have CMake recognize the HDF5 installation?

2条回答
手持菜刀,她持情操
2楼-- · 2019-08-03 07:18

I was using an outdated HDF5 version; the current version is HDF5-1.8.18.

Unfortunately, the VS 2010 x64 generator is missing in the CMake-hdf5-1.8.18 archive. There are only .bat files for VS 2012, 2013 and 2015. It is possible to add other generators though:

  1. Download CMake archive from the HDF5 download website, i.e. from this website. Make sure to take the version you want to install.
  2. Open file HDF5config.cmake
  3. Search for CTEST_CMAKE_GENERATOR
  4. Add another elseif for your desired generator, i.e. for Visual Studio 2010 x64: elseif(${BUILD_GENERATOR} STREQUAL "VS201064") set(CTEST_CMAKE_GENERATOR "Visual Studio 10 2010 Win64")
  5. Create another .bat file, i.e. build-VS2010-64.bat
  6. Replace the BUILD_GENERATOR value with the one that you chose in the HDF5config.cmake file, i.e. ctest -S HDF5config.cmake,BUILD_GENERATOR=VS201064 -C Release -V -O hdf5.log
  7. Run the .bat file
  8. The built HDF5 installation will be available in the folder .\build\_CPack_Packages\win64

After that I changed the CMakeLists lines shown in the original question, as shown in the USING_HDF5_CMake.txt thats created while compilation. Note that I changed C to CXX in the component list because I have C++ project.

set (LIB_TYPE STATIC) # or SHARED
string(TOLOWER ${LIB_TYPE} SEARCH_TYPE)

find_package (HDF5 NAMES hdf5 COMPONENTS CXX ${SEARCH_TYPE})
# find_package (HDF5) # Find non-cmake built HDF5
INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIR})
set (LINK_LIBS ${LINK_LIBS} ${HDF5_CXX_${LIB_TYPE}_LIBRARY})
查看更多
女痞
3楼-- · 2019-08-03 07:18

hdf5 can now be installed on Windows via vcpkg (https://github.com/Microsoft/vcpkg)

Jean

查看更多
登录 后发表回答