在Windows上将HDF5库与CMake一起使用(错误:“找不到HDF5”) [英] Using HDF5 Libraries with CMake on Windows (Error: "Could NOT find HDF5")
问题描述
我想在我的C ++程序中使用HDF5库。我在Windows 7上使用VS 2010 x64编译器和CMake 3.8.0rc2。我安装的HDF5版本是1.8.10(通过运行正式的安装程序安装)。
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").
在我的CMakeLists文件中,添加了以下几行:
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在配置时显示以下错误消息:
CMake shows the following error message upon Configuring:
Could NOT find HDF5 (missing: HDF5_LIBRARIES)
我还添加了环境变量 HDF5_DIR
和 HDF5_ROOT
文件夹 C:\Develop\HDF5\1.8.10
。
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
.
让CMake识别HDF5安装我缺少什么?
What am I missing to have CMake recognize the HDF5 installation?
推荐答案
我正在使用过时的HDF5版本;当前版本为HDF5-1.8.18。
I was using an outdated HDF5 version; the current version is HDF5-1.8.18.
不幸的是,CMake-hdf5-1.8.18存档中缺少VS 2010 x64生成器。 VS 2012、2013和2015仅存在.bat文件。虽然可以添加其他生成器:
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:
- 从HDF5下载网站,即来自此网站。确保采用您要安装的版本。
- 打开文件
HDF5config.cmake
- 搜索
CTEST_CMAKE_GENERATOR
- 为所需的生成器添加另一个
elseif
,即对于Visual Studio 2010 x64:
elseif($ {BUILD_GENERATOR} STREQUAL VS201064)
set(CTEST_CMAKE_GENERATOR Visual Studio 10 2010 Win64) - 创建另一个.bat文件,即
build-VS2010-64.bat
- 将BUILD_GENERATOR值替换为您在
HDF5config.cmake文件
,即ctest -S HDF5config.cmake,BUILD_GENERATOR = VS201064 -C版本-V -O hdf5.log
- 运行.bat文件
- 已构建的HDF5安装将位于文件夹
中。\build\ _CPack_Packages\win64
- Download CMake archive from the HDF5 download website, i.e. from this website. Make sure to take the version you want to install.
- Open file
HDF5config.cmake
- Search for
CTEST_CMAKE_GENERATOR
- 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")
- Create another .bat file, i.e.
build-VS2010-64.bat
- 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
- Run the .bat file
- The built HDF5 installation will be available in the folder
.\build\_CPack_Packages\win64
之后,我更改了原始问题中显示的CMakeLists行,如下所示编译时创建的 USING_HDF5_CMake.txt
。请注意,因为我有C ++项目,所以在组件列表中将 C
更改为 CXX
。
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})
这篇关于在Windows上将HDF5库与CMake一起使用(错误:“找不到HDF5”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!