Cannot Generate an HDF5 File

Hello! Recently I downloaded HDF5 using version 1.14.1-2 with VSCode 17 2022 on Windows 10 with CMake version 3.27.0-rc5 and WiX version 4.0.1+6e6eb478. I intend to use it in C++. Because of these circumstances, I’ve had to make my own CMakeUserPresets.json and change the HDF5config.cmake as it kept getting my presets and version wrong.

After all of that, I’m still not quite getting the results I want from a test file I made. Here is the testfile:

#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;

While this test file doesn’t error and does build, everytime I run it, I get a .exe file with the build output inside (so really just a .txt file coined as an executable). This build output is contains declspec, #pragma warning, and just spits out my main at the bottom with no success or failure message. Instead, I wanted to see an HDF5 file outputted. Here are the main issues I can see:

  • When I attempt to include H5Cpp.h, I get a fatal error saying that H5Cpp.h cannot be found (I checked and it does exist in hdf5-1.14.1-2/c++/src). For kicks I decided to move my test file into that folder, and while it recognized H5Cpp.h, it didn’t recognize hdf5.h within H5Include.h.
  • When I try to set my new presets, CMake errors saying it doesn’t recognize the command cmake --workflow --presets-my-StdShar-Clang. I put in my-StdShar-Clang as that is what I renamed my preset in my CMakeUserPresets.json. For more information on this, review the second method of Section X in INSTALL_CMake.txt under Release_docs in the source folder.
  • With initial install I never got the HDF5-, instead I got a .zip containing some executables that won’t exactly run.

What’s strange is that I installed the python version of HDF5 and ran a test file using that and it worked perfectly. I need to use it in C++, with all of this information where do I go from here?

What you have shown us is the example, we will need to see the CMakeLists.txt file and the build command if you are using cmake to build the example.

The “presets” in the source files is just for building the HDF5 library. To use the library installation to build programs, please see the release_docs/USING_HDF5_CMake.txt file for the process.

I figured it out. I remade my CMakeLists.txt file to be compatible with my test program, VS Code Environments and preexisting builds. Additionally, I tested HDF5Examples where I didn’t before. Thanks for your help, I hope to help anyone else with this issue.