Unable to make HDF5 and HDFView work, both at the same time, neither with the .msi HDF5 installation nor with the vcpkg HDF5 installation

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-…

The most direct solution is to keep HDF5 on your system path, and temporarily modify the local path when executing HDFView. On Windows, if you’re executing HDFView through the command line, you can do this by creating an executable batch file containing the following:

setlocal
REM Remove the HDF5 bin directory from PATH for this launch only.
REM The trailing semicolon must match exactly how it appears in PATH.
set "PATH=%PATH:<exact path from your root drive to the HDF5 binary>;=%"
start "" "<exact path from root to your HDFView.exe>"
endlocal

Running this batch file should then launch HDFView without it being able to find the HDF5 library on your main system PATH.

It’s also possible to achieve your goal by removing HDF5 from your system-wide PATH and then modifying the CMake build process to find it, but this would be more involved, and it’s generally more convenient to keep HDF5 on the PATH anyway.

1 Like

@mlarson Some clarifications:

  • I don’t run HDFView through the command line. I just click on the program icon shortcut with the purpose to make the staring process as agile as possible (not needing to open a terminal, writing the corresponding command, etc.).

  • Seeing that removing HDF5 from the system PATH could not be the more convinient way, then what about the mentioned option in the main post about to work only with the HDF5 vcpkg package installation (no .msi HDF5 installation at all)? Could it be an alternative? possibly being even more simplified for those who work with a package manager?

Thank you for your time!

Don’t put HDF5 on your path. This will only lead to issues down the road. We use VCPKG with HDF5 for our project and it works find. The VCPKG will install into it’s own “sandbox” location. Your C++ project uses that sandbox for linking against.

We use this CMake:

# ------------------------------------------------------------------------------
# Find HDF5
# ------------------------------------------------------------------------------
find_package(HDF5 REQUIRED)
target_link_libraries(simplnx
  PUBLIC
    HDF5::HDF5
)

And that works perfectly fine.

For HDFView we used the HDFView-3.4.1App-Windows.zip download link for Windows.

You really want to keep those environments separate.

Hope that helps

Mike Jackson

1 Like

Since vcpkg does not add HDF5’s install directory onto the system path, HDFView shouldn’t run into any problems with a vcpkg HDF5 installation. The problem you encountered in your first post when trying to use vcpkg is entirely related to the HDF5 dependency resolution process, not HDFView.

The build issue you ran into with HDF5 (Could NOT find HDF5...) is caused by CMake not knowing where HDF5 is, since HDF5 isn’t on the global path. At build time, you should provide cmake with the path to the vcpkg toolchain file in your installation of vcpkg. If you’re building your project through the command line:
cmake -B build -DCMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake

I think the default vcpkg installation of HDF5 lacks the CPP bindings, so you should also make sure you have hdf5cpp installed through vcpkg.

1 Like