Visual c++ 在Visual Studio 2013上使用HDF5启动Visual C++;2013

Visual c++ 在Visual Studio 2013上使用HDF5启动Visual C++;2013,visual-c++,visual-studio-2013,hdf5,Visual C++,Visual Studio 2013,Hdf5,我很难得到一个使用Visual Studio 2013(C++)的HDF5示例。 示例位于:并且为了完整性,我在下面发布了代码 我的第一个问题是:最新的HDF5(版本1.813)是否使用Visual C++ 2013?文档中只提到了我可以看到的2012年,但一般来说,在提到2012年的2013年,我没有遇到任何问题 我尝试将示例程序作为32位和64位应用程序。最终,我对64位感兴趣。在32位的项目设置中,在VC++设置下,我添加到包含目录:C:\Program Files(x86)\HDF\U

我很难得到一个使用Visual Studio 2013(C++)的HDF5示例。 示例位于:并且为了完整性,我在下面发布了代码

我的第一个问题是:最新的HDF5(版本1.813)是否使用Visual C++ 2013?文档中只提到了我可以看到的2012年,但一般来说,在提到2012年的2013年,我没有遇到任何问题

我尝试将示例程序作为32位和64位应用程序。最终,我对64位感兴趣。在32位的项目设置中,在VC++设置下,我添加到包含目录:C:\Program Files(x86)\HDF\U Group\HDF5\1.8.13\include 在库目录中,我添加了:C:\ProgramFiles(x86)\HDF\u Group\HDF5\1.8.13\lib

在Linker->Input中,我添加了:hdf5.lib;hdf5_cpp.lib 当我运行时,我(并非意外地)收到消息,“程序无法启动,因为您的计算机缺少hdf5.dll…” 因此,在调试目录中,我从目录中添加了hdf5.dll和hdf5_cpp.dll: C:\ProgramFiles(x86)\HDF\U组\HDF5\1.8.13\bin

然后我得到运行时错误:

应用程序无法正确启动(0xc000007b)。单击“确定”关闭应用程序。有什么想法吗

顺便说一句,当我尝试x64位版本(使用64位设置、目录和文件)时,我得到了稍微不同的错误。程序一直运行到最后,但没有向控制台写入属性,也没有生成任何文件,最后出现了可怕的错误(在最后一行点击f10之后):

HDF5AttributeExample2.exe中0x000007FEF05E512D(msvcp120d.dll)处未处理的异常:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFF

在这两种情况下(32位和64位),我的直觉告诉我,我有一些配置问题(错误的库,错误的设置,等等),我非常感谢任何人能提供的帮助或建议

如果有另一个Visual C++ HDF5的例子,请告诉我!p> 谢谢

戴夫

#包括
#包括
#包括“H5Cpp.h”
使用std::cout;
使用std::endl;
使用名称空间H5;
常量H5std_字符串文件名(“string_test.h5”);
常数H5std_字符串DS_名称(“数据集1”);
常量H5std_字符串属性名称(“字符串属性”);
内部主(空){
//创建命名文件
H5File file=H5File(文件名,H5F\u ACC\u TRUNC);
//为数据集创建新的数据空间
常数int秩=3;
常数int dim1=2;
常数int dim2=2;
常数int dim3=2;
hsize_t dims[秩]={dim1,dim2,dim3};
数据空间数据空间=数据空间(排名,dims);
//为数据集创建新的数据类型
FloatType数据类型(PredType::NATIVE\u FLOAT);
//创建数据集
DataSet数据集=file.createDataSet(DS_名称、数据类型、数据空间);
//设置写入缓冲区“矩阵”
int q,r,s;
浮动值;
浮点矩阵[dim1][dim2][dim3];
对于(q=0;qCUT

看起来不像太多人对VisualC++中的HDF5感兴趣,用视图的数量来判断。也许这应该是对我的警告!无论如何,对于后人,我提供了以下对我原来问题的回答。 首先,需要非常小心的是,path变量在环境设置中是正确的,并且根据您想要的设置,它在32位或64位时设置正确。
而不是: C:\ProgramFiles(x86)\HDF\U组\HDF5\1.8.13\bin 我有: C:\ProgramFiles(x86)\HDF Group\HDF5\1.8.13\bin(注意缺少下划线)

此外,还需要注意32位(使用程序文件(x86))或64位(使用程序文件)的位置。如果有人知道在使用HDf5的同一台机器上运行32位和64位程序的更简单方法,请告诉我

另一个主要问题是示例代码本身。在其原始形式下,它不起作用。经过多次尝试和错误后,我将问题归结为使用H5std_字符串。当我将其替换为char[]时,一切都起作用。例如,我没有使用: 常量H5std_字符串文件名(“string_test.h5”); 我用过: 字符文件名[128]=“string_test.h5”; 并使用H5文件构造函数,如下所示: H5File file=H5File(文件名,H5F_ACC_TRUNC); 我没有得到编译时错误,这是很烦人的。构造函数声称在H5Frase:Hyror的构造函数中使用STD::string(H5STDYString是什么)。很可能,有些VisualStudio设置使原始代码工作。我对VisualC++的知识不够了解。 无论如何,祝你好运


Dave

您遇到的运行时错误是由于您使用的库是使用VS2012编译的

来自VisualStudio和CMake上的HDF组:

首先,确保您使用的Visual Studio版本与用于创建预构建二进制文件的版本相同。这是避免运行时错误所必需的

我建议您自己尝试使用CMake在VS2013上构建源代码


好的,在我尝试为VS2013 Ultimate编译它之后,我设法使它同时支持32位和64位

  • #include <string>
    #include <iostream>
    
    #include "H5Cpp.h"
    
    using std::cout;
    using std::endl;
    
    using namespace H5;
    
    const H5std_string FILE_NAME("string_test.h5");
     const H5std_string DS_NAME("Data Set 1");
    const H5std_string ATTR_NAME("String Attribute");
    
    int main(void) {
    
    // Create the named file
    H5File file = H5File(FILE_NAME, H5F_ACC_TRUNC);
    
    // Create new dataspace for the dataset
    const int rank = 3;
    const int dim1 = 2;
    const int dim2 = 2;
    const int dim3 = 2;
    hsize_t  dims[rank] = { dim1, dim2, dim3 };
    DataSpace dataspace = DataSpace(rank, dims);
    
    // Create new datatype for the dataset
    FloatType datatype(PredType::NATIVE_FLOAT);
    
    // Create the dataset
    DataSet dataset = file.createDataSet(DS_NAME, datatype, dataspace);
    
    // Set up write buffer 'matrix'
    int q, r, s;
    float value;
    float matrix[dim1][dim2][dim3];
    for (q = 0; q < dim1; q++)
    for (r = 0; r < dim2; r++)
    for (s = 0; s < dim3; s++)
    {
        value = 1.111 + (q * r * s);
        matrix[q][r][s] = value;
    }
    
    // Write data to the dataset
    dataset.write(matrix, datatype);
    
    // Create new dataspace for attribute
    DataSpace attr_dataspace = DataSpace(H5S_SCALAR);
    
    // Create new string datatype for attribute
    StrType strdatatype(PredType::C_S1, 256); // of length 256 characters
    
    // Set up write buffer for attribute
    const H5std_string strwritebuf("This attribute is of type StrType");
    
    // Create attribute and write to it
    Attribute myatt_in = dataset.createAttribute(ATTR_NAME, strdatatype, attr_dataspace);
    myatt_in.write(strdatatype, strwritebuf);
    
    // Set up read buffer for attribute
    H5std_string strreadbuf("");
    
    // Open attribute and read its contents
    Attribute myatt_out = dataset.openAttribute(ATTR_NAME);
    myatt_out.read(strdatatype, strreadbuf);
    
    // Display attribute contents
    cout << "Attribute contents: " << strreadbuf << endl;
    
    return 0;
    }