I am using visual studio project 2019- and vcpkg in order to load data to CUDA 11.6 C++ visual studio project.
at the begining of the file i have :
// #define H5_BUILT_AS_DYNAMIC_LIB
#include <H5Cpp.h>
and it do not give any errors - so I assume it was correctly loaded and integrated by by vcpkg. Also as visible at the end of the post H5 files are visible in external dependencies list of a solution explorer.
simple code that leads to error is shown below
H5::H5File file(FILE_NAME, H5F_ACC_RDONLY);
H5::DataSet dset = file.openDataSet(DATASET_NAME);
error (set of unresolved external symbol errors) - it appears in compile time.
If I will uncomment #define H5_BUILT_AS_DYNAMIC_LIB 1 the error discussed above disappears but new shows (in runtime) -
hdf5_cpp_D.dll not found ...
Exactly the same code worked perfectly well on my cmake CUDA C++ project, but for various reasons I need to switch to visual studio project.
Minimal example giving error
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
//#define H5_BUILT_AS_DYNAMIC_LIB 1
#include <H5Cpp.h>
#include <stdio.h>
void loadHDFIntoBoolArr(H5std_string FILE_NAME, H5std_string DATASET_NAME, bool*& data) {
H5::H5File file(FILE_NAME, H5F_ACC_RDONLY);
H5::DataSet dset = file.openDataSet(DATASET_NAME);
/*
* Get the class of the datatype that is used by the dataset.
*/
H5T_class_t type_class = dset.getTypeClass();
H5::DataSpace dspace = dset.getSpace();
int rank = dspace.getSimpleExtentNdims();
hsize_t dims[2];
rank = dspace.getSimpleExtentDims(dims, NULL); // rank = 1
printf("Datasize: %d \n ", dims[0]); // this is the correct number of values
// Define the memory dataspace
hsize_t dimsm[1];
dimsm[0] = dims[0];
H5::DataSpace memspace(1, dimsm);
data = (bool*)calloc(dims[0], sizeof(bool));
dset.read(data, H5::PredType::NATIVE_HBOOL, memspace, dspace);
file.close();
}
void loadHDF() {
const int WIDTH = 512;
const int HEIGHT = 512;
const int DEPTH = 826;
const H5std_string FILE_NAMEonlyLungsBoolFlat("C:\\Users\\1\\PycharmProjects\\pythonProject3\\mytestfile.hdf5");
const H5std_string DATASET_NAMEonlyLungsBoolFlat("onlyLungsBoolFlat");
// create a vector the same size as the dataset
bool* onlyLungsBoolFlat;
loadHDFIntoBoolArr(FILE_NAMEonlyLungsBoolFlat, DATASET_NAMEonlyLungsBoolFlat, onlyLungsBoolFlat);
}
int main()
{
loadHDF();
return 0;
}
vcpk commands used
.\vcpkg install hdf5
.\vcpkg install hdf5[cpp]
.\vcpkg integrate install
The solution in my situation was simple just reinstall windows - on fresh installation I did steps as mentioned at the begining and all works now