I am trying to read HDF5 file, this's the first time I come across this file format so please bare with me. The issue that I am having right now is linking the hdf5 lib to my project on Visual Studio 2017. This's what I've done so far:
Following the steps of the solution proposed here.
However, I still have the following linker errors when I try to build my project.
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: __cdecl H5::DataSpace::DataSpace(int,unsigned __int64 const *,unsigned __int64 const *)" (??0DataSpace@H5@@QEAA@HPEB_K0@Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: int __cdecl H5::DataSpace::getSimpleExtentDims(unsigned __int64 *,unsigned __int64 *)const " (?getSimpleExtentDims@DataSpace@H5@@QEBAHPEA_K0@Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl H5::DataSpace::~DataSpace(void)" (??1DataSpace@H5@@UEAA@XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: class H5::DataSet __cdecl H5::H5Location::openDataSet(char const *,class H5::DSetAccPropList const &)const " (?openDataSet@H5Location@H5@@QEBA?AVDataSet@2@PEBDAEBVDSetAccPropList@2@@Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: enum H5T_class_t __cdecl H5::AbstractDs::getTypeClass(void)const " (?getTypeClass@AbstractDs@H5@@QEBA?AW4H5T_class_t@@XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual class H5::DataSpace __cdecl H5::DataSet::getSpace(void)const " (?getSpace@DataSet@H5@@UEBA?AVDataSpace@2@XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: void __cdecl H5::DataSet::read(void *,class H5::DataType const &,class H5::DataSpace const &,class H5::DataSpace const &,class H5::DSetMemXferPropList const &)const " (?read@DataSet@H5@@QEBAXPEAXAEBVDataType@2@AEBVDataSpace@2@2AEBVDSetMemXferPropList@2@@Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl H5::DataSet::~DataSet(void)" (??1DataSet@H5@@UEAA@XZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: __cdecl H5::H5File::H5File(char const *,unsigned int,class H5::FileCreatPropList const &,class H5::FileAccPropList const &)" (??0H5File@H5@@QEAA@PEBDIAEBVFileCreatPropList@1@AEBVFileAccPropList@1@@Z) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual void __cdecl H5::H5File::close(void)" (?close@H5File@H5@@UEAAXXZ) referenced in function main
1>EigenExperiment.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl H5::H5File::~H5File(void)" (??1H5File@H5@@UEAA@XZ) referenced in function main
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::DataSpace const & const H5::DataSpace::ALL" (?ALL@DataSpace@H5@@2AEBV12@EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT" (?DEFAULT@FileAccPropList@H5@@2AEBV12@EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::FileCreatPropList const & const H5::FileCreatPropList::DEFAULT" (?DEFAULT@FileCreatPropList@H5@@2AEBV12@EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::DSetMemXferPropList const & const H5::DSetMemXferPropList::DEFAULT" (?DEFAULT@DSetMemXferPropList@H5@@2AEBV12@EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::DSetAccPropList const & const H5::DSetAccPropList::DEFAULT" (?DEFAULT@DSetAccPropList@H5@@2AEBV12@EB)
1>EigenExperiment.obj : error LNK2001: unresolved external symbol "public: static class H5::PredType const & const H5::PredType::NATIVE_FLOAT" (?NATIVE_FLOAT@PredType@H5@@2AEBV12@EB)
1>C:\Users\maxim\source\repos\EigenExperiment\x64\Debug\EigenExperiment.exe : fatal error LNK1120: 17 unresolved externals
1>Done building project "EigenExperiment.vcxproj" -- FAILED.
Also, I've attached the code I'm using, just in case I missed something. Any hep is highly appreciated :)
#include <iostream>
#include <Eigen/Dense>
#include <filesystem>
#include <math.h>
#include "H5Cpp.h"
#include <vector>
#include <string>
using namespace std;
using namespace H5;
int main()
{
string ifn = "basler.h5";
string datasetPath = "/face_g_tobii/data";
// Open HDF5 file handle, read only
H5File fp(ifn.c_str(), H5F_ACC_RDONLY);
// access the required dataset by path name
DataSet dset = fp.openDataSet(datasetPath.c_str());
// get the dataspace
DataSpace dspace = dset.getSpace();
// get the dataset type class
H5T_class_t type_class = dset.getTypeClass();
// According to HDFView, this is a 32-bit floating-point
// get the size of the dataset
hsize_t rank;
hsize_t dims[2];
rank = dspace.getSimpleExtentDims(dims, NULL); // rank = 1
cout << "Datasize: " << dims[0] << endl; // this is the correct number of values
// Define the memory dataspace
hsize_t dimsm[1];
dimsm[0] = dims[0];
DataSpace memspace(1, dimsm);
// create a vector the same size as the dataset
vector<float> data;
data.resize(dims[0]);
cout << "Vectsize: " << data.size() << endl;
float data_out[65341];
for (int i = 0; i < 65341; i++)
{
data_out[i] = 0;
}
// pass pointer to the array (or vector) to read function, along with the data type and space.
dset.read(data_out, PredType::NATIVE_FLOAT, memspace, dspace); // FAILS
dset.read(data_out, PredType::NATIVE_FLOAT, dspace); // FAILS
dset.read(data.data(), PredType::NATIVE_FLOAT, memspace, dspace); // FAILS
// close the HDF5 file
fp.close();
}
It turned out the external libraries should be named first, what worked for me was:
1.4 Select Linker->Input and beginning with the "Additional Dependencies" line, enter the library names. The external libraries should be listed first, followed by the HDF5 library, and then optionally the HDF5 High Level, Fortran or C++ libraries. For example, to compile a C++ application, enter:
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib
This's from the documentation of HDF5, which I completely overlooked :/