Trouble linking and using HDF5 C++ API with Visual Studio 2022 (version 1.14.6)

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:

  1. Added H5_BUILT_AS_DYNAMIC_LIB to the Preprocessor Definitions.
  2. Added the include folder path to Additional Include Directories.
  3. Added the lib folder path to Additional Library Directories.
  4. 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
  1. 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!

You might need to add the path of the dlls to the %PATH% env var?

Successfully created a file by directly specifying the file path as an argument. However, the following warning messages appear. Do you happen to know how to resolve them?

1>HDF5Sample_CPP.cpp
1>C:\Users\Mee\source\repos\HDF5Sample_CPP\HDF5Sample_CPP\vendor\hdf5_1_14_6\include\H5Exception.h(84,18): warning C4251: ‘H5::Exception::detail_message’: ‘std::basic_string<char,std::char_traits,std::allocator>’ needs to have dll-interface to be used by clients of ‘H5::Exception’
1>(compiling source file ‘HDF5Sample_CPP.cpp’)
1> C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.43.34808\include\xstring(522,7):
1> see declaration of ‘std::basic_string<char,std::char_traits,std::allocator>’
1>C:\Users\Mee\source\repos\HDF5Sample_CPP\HDF5Sample_CPP\vendor\hdf5_1_14_6\include\H5Exception.h(85,18): warning C4251: ‘H5::Exception::func_name’: ‘std::basic_string<char,std::char_traits,std::allocator>’ needs to have dll-interface to be used by clients of ‘H5::Exception’
1>(compiling source file ‘HDF5Sample_CPP.cpp’)
1> C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.43.34808\include\xstring(522,7):
1> see declaration of ‘std::basic_string<char,std::char_traits,std::allocator>’
1>HDF5Sample_CPP.vcxproj → C:\Users\Mee\source\repos\HDF5Sample_CPP\x64\Debug\HDF5Sample_CPP.exe
1>Done building project “HDF5Sample_CPP.vcxproj”