I am having a hard time getting an HDF5 example working with Visual Studio 2013 (C++). The example is at: http://www.hdfgroup.org/ftp/HDF5/examples/misc-examples/stratt.cpp and I've posted the code below for completeness.
My first question is: Will the latest HDF5 (version 1.8.13) work with Visual C++ 2013? The docs only mention 2012 that I can see, but generally I've had no problems using 2013 where 2012 is mentioned.
I tried the example program as both a 32 bit and a 64 bit app. Ultimately, I'm interested in 64 bit. In the project settings for 32 bit, under VC++ settings, I added to the include directories: C:\Program Files (x86)\HDF_Group\HDF5\1.8.13\include To the library directories, I added: C:\Program Files (x86)\HDF_Group\HDF5\1.8.13\lib
To the Linker->Input, I added: hdf5.lib;hdf5_cpp.lib When I ran, I (not unexpectedly) got the message, "The program can't start because hdf5.dll is missing from your computer..." So to the debug directory, I added, hdf5.dll and hdf5_cpp.dll from the directory: C:\Program Files (x86)\HDF_Group\HDF5\1.8.13\bin
I then get the runtime error:
The application was unable to start correctly (0xc000007b). Click OK to close the application. Any ideas?
Incidentally, when I tried the x64 bit version (using the 64 bit setttings, directories and files), I got slightly different errors. The program runs to the end, but no attribute is written to the console, no file is produced, and I get the dreaded error at the end (after hitting f10 on the last line):
Unhandled exception at 0x000007FEF05E512D (msvcp120d.dll) in HDF5AttributeExample2.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
In both cases (32 and 64 bit) my gut tells me that I have some sort of configuration problem (wrong lib, wrong setup, etc.) I'd really appreciate any help or suggestions folks can offer.
If there is another Visual C++ HDF5 example, by all means please tell me!
Thanks,
Dave
#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;
}
The runtime error that you are getting arises from the fact that you are using libraries that were compiled with VS2012.
From the HDF Group website on VisualStudio and CMake:
First, make sure you use the same version of Visual Studio that was used to create the pre-built binaries. This is required to avoid runtime errors.
I suggest that you try by yourself to build the source code on VS2013 using CMake.
Ok, after having tried myself to compile it for the VS2013 Ultimate I managed to get it working with both 32 bit and 64 bit support.
cpack -C {Debug | Release} ---config C:\...\"build"\CPackConfig.cmake
. This will create an installer for the files.C:\Program Files (x86)\HDF_Group\HDF5\1.8.13\include
. Change this path accordingly. If you are using a x64 version, you will need to change the platform on top of this window to x64. If it doesn't exist, click on Configuration Manager and from the Active Solution platform drop down menu choose New. Add the x64 option.C:\Program Files (x86)\HDF_Group\HDF5\1.8.13\lib
. Change this also accordingly. Note that if you built the binaries for x64 they will be installed at C:\Program Files\HDF_Group\HDF5\1.8.13\
.Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With