I’m trying to work with HDF5 in a cpp program and at the same time also with HDFView (v3.4.1, currently the most recent version).
I’m new with HDF5 and currently I’m trying to work with the next program example:
h5tutr_crtdat.cpp
The situation is the next:
Initially I had the .msi HDF5 installation and a C++ project for the h5tutr_crtdat.cpp program was compiling and generating the corresponding .h5 file, but in that case the HDFView didn’t open showing the error “failed to launch JVM” (already documented as “Known Problems In This Release”).
CMakeLists.txt for that initial case:
cmake_minimum_required(VERSION 3.10.0)
project(test_0 VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 23)
enable_testing()
find_package(HDF5 REQUIRED COMPONENTS CXX)
include_directories(${HDF5_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} h5tutr_crtdat.cpp)
target_link_libraries(${PROJECT_NAME} ${HDF5_LIBRARIES} ${HDF5_C_LIBRARIES})
The next test was following one of the documented “solutions” in order to be able to open HDFView: “… removing those directories from the PATH” (removing the HDF5 directory in the “path” of the System Environment Variables), and in that other case HDFView has been able to open (no errors and reading a .h5 file), BUT, with this “solution” applied, then the project for the h5tutr_crtdat.cpp program doesn’t compile (because the missing “path” directory).
So, looking for a way to be able to work with HDF5 and HDFView, both at the same time, then the next test has been:
- Keeping the previous status, with no HDF5 directory in the “path”.
- Installing HDF5 from vcpkg and uninstalling the .msi HDF5 general installation.
But, with the next CMakeLists.txt file, now the cpp project doesn’t compile.
CMakeLists.txt currently:
cmake_minimum_required(VERSION 3.10.0)
project(test_0 VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# find_package(HDF5 REQUIRED COMPONENTS CXX)
find_package(HDF5 COMPONENTS CXX)
# find_package(hdf5 COMPONENTS CXX)
# include_directories(${HDF5_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} h5tutr_crtdat.cpp)
# target_link_libraries(${PROJECT_NAME} ${HDF5_LIBRARIES} ${HDF5_C_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE HDF5::HDF5)
# target_link_libraries(${PROJECT_NAME} PRIVATE hdf5::hdf5)
Output:
...
[cmake] -- Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS CXX)
[cmake] -- Configuring done (6.4s)
[cmake] CMake Error at CMakeLists.txt:... (target_link_libraries):
[cmake] Target "test_0" links to:
[cmake]
[cmake] HDF5::HDF5
[cmake]
[cmake] but the target was not found. Possible reasons include:
[cmake]
[cmake] * There is a typo in the target name.
[cmake] * A find_package call is missing for an IMPORTED target.
[cmake] * An ALIAS target is missing.
...
Host Environment:
- Host: x64-windows
- Compiler: MSVC 19.50.35729 for x64
- vcpkg version: 2026-05-27-…
