Hello,
I’m trying to use the HDF5 C++ API in my project with Visual Studio 2022 on Windows, but I’m having trouble getting it to work properly.
I downloaded the following pre-built binary from the HDF Group website:
hdf5-1.14.6-win-vs2022_intel.zip
My Goal:
I want to use the HDF5 C++ API (H5::H5File
) in my C++ project to create and manipulate .h5
files.
What I Did:
After extracting the ZIP file, I set up my Visual Studio project as follows:
- Added
H5_BUILT_AS_DYNAMIC_LIB
to the Preprocessor Definitions. - Added the
include
folder path to Additional Include Directories. - Added the
lib
folder path to Additional Library Directories. - Added the following
.lib
files to Additional Dependencies:
hdf5_hl_cpp.lib
hdf5_cpp.lib
hdf5_hl_fortran.lib
hdf5_fortran.lib
hdf5_hl.lib
hdf5.lib
- Copied all files from the
bin
folder to the same directory as my application.exe
.
MyCode
#include <iostream>
#include <H5Cpp.h>
const H5std_string FILE_NAME("myTest.h5");
void WriteH5File()
{
try
{
H5::H5File file(FILE_NAME, H5F_ACC_TRUNC);
}
catch (H5::FileIException error)
{
return;
}
catch (H5::GroupIException error)
{
return;
}
}
int main()
{
WriteH5File();
return 0;
}
The Problem:
The program builds successfully, but at runtime it fails to create the file. I suspect my library configuration may be incorrect. I would appreciate it if someone could check if my setup steps are correct, or let me know if I missed anything important.
Thank you in advance!