c++ - 从 HDF5 文件链接器问题读取
问题描述
我正在尝试读取 HDF5 文件,这是我第一次遇到这种文件格式,所以请与我联系。我现在遇到的问题是将 hdf5 lib 链接到我在 Visual Studio 2017 上的项目。这就是我到目前为止所做的:
- Linker > Input > Additional Dependencies 包含 hdf5.lib
- Linker > General > Additional Libraries Directories 包含我的 HDF5 安装的 lib 目录的路径
- C/C++ > General > Additional Include Directories 包含包含我的 HDF5 安装目录的路径
- 我已添加到我的 HDF5 安装的 PATH 变量 bin 目录
遵循此处提出的解决方案的步骤。
但是,当我尝试构建我的项目时,我仍然遇到以下链接器错误。
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.
另外,我附上了我正在使用的代码,以防我错过了什么。任何 hep 都受到高度赞赏:)
#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();
}
解决方案
原来应该首先命名外部库,对我有用的是:
1.4 选择 Linker->Input 并从“Additional Dependencies”行开始,输入库名称。应首先列出外部库,然后是 HDF5 库,然后是可选的 HDF5 高级、Fortran 或 C++ 库。例如,要编译 C++ 应用程序,请输入:
szip.lib zlib.lib hdf5.lib hdf5_cpp.lib
这是来自我完全忽略的 HDF5 的文档:/
推荐阅读
- javascript - 如何比较摩卡中的两个数组?
- r - 为什么 tibble 会在从矩阵创建的新列名中添加“[, 1]”?
- regex - 当前面没有字符串时,正则表达式匹配字符
- python - Python Autologin 无法编译
- java - JDBC 模板表锁定问题
- javascript - 在 .where 中使用 firebase .update(而不是 .doc)
- image - 如何在 Keras 中将顺序模型添加到预训练模型?
- javascript - Mongoose.post 路由似乎只有在出现错误时才会被调用,但是当没有错误时它不会被调用
- android - 为什么 LicenseCheckerCallback 的方法 allow 应该返回 RETRY 和 NOT_LICENSED?
- python - pip 可以在 Windows 10 上安装 webrtcvad 吗?