读取 HDF5 文件链接器问题
Reading from HDF5 file linker issue
我正在尝试读取 HDF5 文件,这是我第一次遇到这种文件格式,所以请多多包涵。我现在遇到的问题是将 hdf5 库链接到我在 Visual Studio 2017 上的项目。
这是我到目前为止所做的:
- 链接器 > 输入 > 附加依赖项包含 hdf5.lib
- Linker > General > Additional Libraries Directories 包含我的 HDF5 安装的 lib 目录的路径
- C/C++ > General > Additional Include Directories 包含包含我的 HDF5 安装目录的路径
- 我已经添加到我的 HDF5 安装的 PATH 变量 bin 目录中
按照建议的解决方案的步骤进行here。
但是,当我尝试构建我的项目时,仍然出现以下链接器错误。
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.
另外,我附上了我正在使用的代码,以防我遗漏了什么。
非常感谢任何帮助:)
#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();
}
根据报错,你建的工程是x64版本,建议你检查下链接的hdf5.lib是32位还是64位的?你应该使用 64 位的 hdf5.
而且我建议你可以尝试检查 属性 页面中的平台和配置 selection 是否为 x64
和 debug
.
我建议您在更改属性时可以 select 将平台设为“所有平台”,将配置设为 select “所有配置”。
原来应该首先命名外部库,对我有用的是:
1.4 Select 链接器->输入并以
“Additional Dependencies”行,输入库名。这
应该首先列出外部库,然后是 HDF5
库,然后是可选的 HDF5 高级、Fortran 或 C++
图书馆。例如,要编译 C++ 应用程序,请输入:
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib
这是来自 HDF5 的文档,我完全忽略了它:/
我正在尝试在 vs2019 上为 c++ 使用 hdf5,我做了添加的事情
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib 但是后来我找不到库 szip 和 zlib。当然,我在预处理器中做了“H5_BUILT_AS_DYNAMIC_LIB”,但什么也没做。
我正在尝试读取 HDF5 文件,这是我第一次遇到这种文件格式,所以请多多包涵。我现在遇到的问题是将 hdf5 库链接到我在 Visual Studio 2017 上的项目。 这是我到目前为止所做的:
- 链接器 > 输入 > 附加依赖项包含 hdf5.lib
- Linker > General > Additional Libraries Directories 包含我的 HDF5 安装的 lib 目录的路径
- C/C++ > General > Additional Include Directories 包含包含我的 HDF5 安装目录的路径
- 我已经添加到我的 HDF5 安装的 PATH 变量 bin 目录中
按照建议的解决方案的步骤进行here。
但是,当我尝试构建我的项目时,仍然出现以下链接器错误。
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.
另外,我附上了我正在使用的代码,以防我遗漏了什么。 非常感谢任何帮助:)
#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();
}
根据报错,你建的工程是x64版本,建议你检查下链接的hdf5.lib是32位还是64位的?你应该使用 64 位的 hdf5.
而且我建议你可以尝试检查 属性 页面中的平台和配置 selection 是否为 x64
和 debug
.
我建议您在更改属性时可以 select 将平台设为“所有平台”,将配置设为 select “所有配置”。
原来应该首先命名外部库,对我有用的是:
1.4 Select 链接器->输入并以 “Additional Dependencies”行,输入库名。这 应该首先列出外部库,然后是 HDF5 库,然后是可选的 HDF5 高级、Fortran 或 C++ 图书馆。例如,要编译 C++ 应用程序,请输入:
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib
这是来自 HDF5 的文档,我完全忽略了它:/
我正在尝试在 vs2019 上为 c++ 使用 hdf5,我做了添加的事情 szip.lib zlib.lib hdf5.lib hdf5_cpp.lib 但是后来我找不到库 szip 和 zlib。当然,我在预处理器中做了“H5_BUILT_AS_DYNAMIC_LIB”,但什么也没做。