【问题标题】:Reading from HDF5 file linker issue从 HDF5 文件链接器问题中读取
【发布时间】:2021-07-11 07:05:04
【问题描述】:

我正在尝试读取 HDF5 文件,这是我第一次遇到这种文件格式,所以请多多包涵。我现在遇到的问题是将 hdf5 库链接到我在 Visual Studio 2017 上的项目。 这是我到目前为止所做的:

  1. 链接器 > 输入 > 附加依赖项包含 hdf5.lib
  2. 链接器 > 常规 > 附加库目录包含我的 HDF5 安装的 lib 目录的路径
  3. C/C++ > General > Additional Include Directories 包含包含我的 HDF5 安装目录的路径
  4. 我已添加到我的 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.

另外,我附上了我正在使用的代码,以防我遗漏了什么。 任何 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();
}

【问题讨论】:

    标签: c++ visual-studio hdfs linker-errors hdf5


    【解决方案1】:

    根据报错,你建的项目是x64版本,建议你检查下链接的hdf5.lib是32位还是64位?您应该使用 64 位 hdf5。

    我建议你可以尝试检查一下平台和属性页中的配置选择是否是x64debug

    我建议您可以在更改属性时为平台选择“所有平台”,并为配置选择“所有配置”。

    【讨论】:

    • 感谢您的评论,我使用的是正确的版本。我只是没有链接所有需要的外部库:)
    【解决方案2】:

    原来应该先命名外部库,对我有用的是:

    1.4 选择 Linker->Input 并以 “附加依赖项”行,输入库名称。这 应首先列出外部库,然后是 HDF5 库,然后是可选的 HDF5 高级、Fortran 或 C++ 图书馆。例如,要编译 C++ 应用程序,请输入:

          szip.lib zlib.lib hdf5.lib hdf5_cpp.lib
    

    这是来自 HDF5 的文档,我完全忽略了:/

    【讨论】:

      【解决方案3】:

      我在 vs2019 上尝试使用 hdf5 for c++,我做了添加的东西 szip.lib zlib.lib hdf5.lib hdf5_cpp.lib 但是我找不到库 szip 和 zlib。当然,我在预处理器上做了“H5_BUILT_AS_DYNAMIC_LIB”,但什么也没做。

      【讨论】:

        猜你喜欢
        • 2016-10-24
        • 2023-04-05
        • 2019-09-22
        • 1970-01-01
        • 2016-06-18
        • 2017-06-26
        • 2015-03-19
        • 1970-01-01
        • 2021-06-04
        相关资源
        最近更新 更多