Fatal error: 'H5Cpp.h' file not found

I’ve carefully gone through the entire process of installing Cmake and now I’m almost done with HDF5 installation (which I’ve done multiple times to be sure), however I’m finding that I can’t do the last step of running the final executable as I don’t get an executable, I get a .zip. Specifically, I am to install the HDF5-1.14.1-2-win64 executable, but only end up with a random zip file containing no executable. I found this issue as it deceptively seemed like HDF5 was completely installed so I made a test file. When I ran the test file, I ran into errors on the first include with the following error message:

fatal error: 'H5Cpp.h' file not found
#include <H5Cpp.h>

To fix the issue I also tried this:

cmake -C hdf5-1.14.1-2/config/cmake/cacheinit.cmake -G "Visual Studio 17 2022"

But got:

ERROR! HDF5 DOES NOT SUPPORT IN SOURCE BUILDS!

What does this mean and is it truly a problem with the executable, or could it be something else entirely?

P.S.: I’m working on Windows

Assumptions; using a CMake >=3.18, You are using the either a source.zip file downloaded from HDF5 website or are using the source from the release tag in the hdf5 repo. You have creaated a build dir and are executing the commands for cmake from there. (According to the last error, this seems to be one of the problems)

Seeing that you are building from source, you are using the steps in release_docs/INSTALL_CMake.txt and for windows, There are two sections for consideration:

Section II. Quick Step Building HDF5 Libraries with CMake Script Mode
Or for more flexibility
Section V. Options for Building HDF5 Libraries with the CMake Command Line

There is a newer method if you are using CMake >=3.23; presets. This is described (not fully vetted by users yet) in section X: Using CMakePresets.json for compiling. here is the relevant steps:
HDF-provided CMakePresets.json

The CMakePresets.json provided by HDF requires CMake version 3.25, which supports package
and workflow presets, and ninja build system. The top-level configuration group is intended to be
a standard set of options to produce a package of shared and staic libraries and tools. Other configurations
used for inheriting settings are in the included json file in “config/cmake-presets/hidden-presets.json”.

Available configurations presets can be displayed by executing:
cmake -S “path-to-source” --list-presets

Using individual command presets (where “compiler-type” is GNUC or MSVC or Clang):
change directory to the hdf5 source folder
cmake --presets=ci-StdShar-“compiler-type”
cmake --build --presets=ci-StdShar-“compiler-type”
ctest --presets=ci-StdShar-“compiler-type”
cpack --presets=ci-StdShar-“compiler-type”

Using the workflow preset to configure, build, test and package the standard configuration is:
change directory to the hdf5 source folder
execute “cmake --workflow --presets=ci-StdShar-“compiler-type” --fresh”
where “compiler-type” is GNUC or MSVC or Clang

For windows: cmake --workflow --presets=ci-StdShar-MSVC --fresh

1 Like

Hi byrn, thank you for the reply it’s super helpful! I checked my Cmake version and it’s 3.28.0, so I tried using the workflow command given in your reply. However, I’m running into this:

cmake --workflow --presets=ci-StdShar-Clang --fresh                                                                              
Unknown argument --presets=ci-StdShar-Clang
Usage: cmake --workflow [options]
Options:
  --preset <preset> = Workflow preset to execute.
  --list-presets    = List available workflow presets.
  --fresh           = Configure a fresh build tree, removing any existing cache file.

To combat this I looked at the list of presets and it looks relatively normal:

-S "path_to_source" --list-presets    
Available configure presets:

  "ci-StdShar-MSVC"
  "ci-StdShar-MSVC-Fortran"
  "ci-StdShar-Clang"

I definitely use Clang as my compiler, and I tried putting Clang in quotation marks along with the entire preset when executing the command, but found the same error. What could be causing this issue?

Did you try the MSVC version – the clang one might need more work/changes on windows.

I tried that it didn’t work…

Strange because we use it in our CI, see .github/workflows/cmake-ctest.yml file.

You might need to go back to the other way.

Ok, how would I go about switching back?

Try section II in release_docs/INSTALL_CMake.txt, first.

I tried that and it didn’t work, so I decided to uninstall all of it and try again, but now the test files won’t even build as the executables aren’t being generated. I’m getting this error specficially:

ctest -S HDF5config.cmake,BUILD_GENERATOR=VS201564 -C Release -V -O hdf5.log
-- Dashboard script configuration:
  CTEST_SITE=[WIN7VS201564.XXXX]  
  CTEST_BUILD_NAME=[Windows-WIN10-vs2015]
  CTEST_SOURCE_DIRECTORY=["correct path"]
  CTEST_BINARY_DIRECTORY=["correct path"]
  CTEST_CMAKE_GENERATOR=[Visual Studio 14 2015 Win64]
  CTEST_CONFIGURATION_TYPE=[Release]
  CTEST_GIT_COMMAND=[]
  CTEST_CHECKOUT_COMMAND=[]
  CTEST_CONFIGURE_COMMAND=["correct path" -DCMAKE_BUILD_TYPE:STRING=Release  -DHDF5_BUILD_FORTRAN:BOOL=OFF -DHDF5_BUILD_JAVA:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=%ProgramFiles%/HDF_Group/HDF5/1.14.1 -DHDF5_ALLOW_EXTERNAL_SUPPORT:STRING=TGZ -DTGZPATH:PATH="correct path"-DHDF5_PACKAGE_EXTLIBS:BOOL=ON -DSITE:STRING=WIN7VS201564.XXXX -DBUILDNAME:STRING=Windows-WIN10-vs2015 -DCTEST_USE_LAUNCHERS:BOOL=OFF "-GVisual Studio 14 2015 Win64" "" "" "correct path"]
  CTEST_SCRIPT_DIRECTORY=["correct path"]
  CTEST_USE_LAUNCHERS=[0]


Run dashboard with model Experimental
   Source directory: "correct path"
   Build directory: "correct path"
   Group: Experimental
   Reading ctest configuration file: "correct path"
   Build name: Windows-WIN10-vs2015
   Use Experimental tag: 20230719-2052
Configure project
   Each . represents 1024 bytes of output
    ... Size of output: 2K
Error(s) when configuring the project
Build project
   Each symbol represents 1024 bytes of output.
   '!' represents an error and '*' a warning.
    . Size of output: 0K
Error(s) when building project
   1 Compiler errors
   1 Compiler warnings
Test project "correct path"
No tests were found!!!

The more verbose output produced:

CPack Error: CPack generator not specified
CPack: Enable Verbose
CPack Verbose: Read CPack config file:

How can I fix this? I already ran CMake config and generate, and it isn’t working. Apologies for the simple question, I’m inexperienced in this field.

I’ve fixed this issue, but still have the fatal error I initially mentioned in my post. I have a feeling I’m running my file incorrectly. Here is my full testHDFER.cpp:

#include <cstdio>
#include <cstdlib>

//#define H5_BUILT_AS_DYNAMIC_LIB 1 // In Windows, turn on this when using hdf5 as a shared library.
#include <H5Cpp.h>

int main() {
    printf("Hello, World!\
");
    const std::string fileName("test.h5");
    H5::H5File file(fileName, H5F_ACC_TRUNC);
    printf("File creation is done.\
");
    return EXIT_SUCCESS;
}

I’m thinking the fatal error is due to my CMake version being 3.27.0-rc5, instead of 3.25, so I’m trying to make my own configurations using the second method described in the X section of INSTALL_CMake.txt. I made CMakeUserPresets.json, and tried to do the steps to set the preset via command line with my-StdShar-clang but it says:

cmake --presets=my-StdShar-Clang
CMake Error: Unknown argument --presets=ci-StdShar-<compiler-type>
CMake Error: Run 'cmake --help' for all supported options.

How can I fix this/what commands should I put instead?

Otherwise, I’m thinking it could be how I’m running it in command line. How can I run testHDFER.cpp using CMake and HDF5 in command line?

Is there a reason you are using VS2015, 1.14.x expects a C99 compliant compiler. VS2019 and VS2022 are better in that regard.

I changed the version, and manually changed some things in the HDF5config.cmake file to set the build the way I want it to work and now it runs, but still doesn’t recognize the H5Cpp.h file. I commented that out and did this instead:

#include <cstdio>
#include <cstdlib>

#define H5_BUILT_AS_DYNAMIC_LIB 1 // In Windows, turn on this when using hdf5 as a shared library.
//#include <H5Cpp.h>

int main() {
    printf("Hello, World!\
");
    const std::string fileName("test.h5");
    H5::H5File file(fileName, H5F_ACC_TRUNC);
    printf("File creation is done.\
");
    return EXIT_SUCCESS;
}

Although this didn’t error, I’m not using hdf5 as a shared library. Nonetheless I ran the test file and it didn’t error, but produced a testHDFer.exe (really a 7000 line .txt file that could open and read it in VSCode) with the build output. It is filled with declspec, #pragma warning and just spits out my main at the bottom with no success or failure message. What does this mean, and where do I go from here?

Maybe someone else can respond as I’m not familiar enough with C++.