I’m looking to add HDF5 support to an application, and have worked through some of the C++ introductory examples. Things work, except for the inability to use H5std_string
.
When invoking HDF5 through CMake I get the following output, one thing to note is that I am using HDF5 through Anaconda, which I recently made sure were up to date.
Below I show how I specify the use of HDF5 in CMake, and how I implement the example in my code. If I replace H5std_string
with just std::string
, the examples work. But given how often examples and documentation invoke H5std_string
I would like to figure out what is causing my issue and how I might resolve it.
Thank you for any help/guidance you can give.
Relevant snippets from CMakeLists.txt
:
if(USE_HDF5) # Provide HDF5 libraries
find_package(HDF5 "1.10.4" REQUIRED COMPONENTS C CXX HL)
if(HDF5_FOUND)
message(STATUS "HDF5 version: ${HDF5_VERSION}")
message(STATUS "HDF5 include dir: ${HDF5_INCLUDE_DIRS}")
message(STATUS "HDF5 CXX lib: ${HDF5_CXX_LIBRARIES}")
include_directories(${HDF5_INCLUDE_DIRS})
target_link_libraries(pce_eval ${HDF5_CXX_LIBRARIES})
add_definitions(-DUSE_HDF5)
else()
# Download HDF5 library and define hdf5_local TODO
# ...
endif()
endif(USE_HDF5)
Output when building specifiying libraries/version.
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5: Using hdf5 compiler wrapper to determine CXX configuration
-- HDF5 version: 1.10.4
-- HDF5 include dir: /Users/chase/anaconda3/include
-- HDF5 CXX lib: /Users/chase/anaconda3/lib/libhdf5_cpp.dylib;/Users/chase/anaconda3/lib/libhdf5.dylib;/usr/lib/libpthread.dylib;/Users/chase/anaconda3/lib/libz.dylib;/usr/lib/libdl.dylib;/usr/lib/libm.dylib
Implementation of h5tutr_crtdat.cpp
in my code:
#ifdef USE_HDF5
#include "H5Cpp.h"
using namespace H5;
const H5std_string FILE_NAME("h5tutr_dset.h5");
const H5std_string DATASET_NAME("dset");
const int NX = 4; // dataset dimensions
const int NY = 6;
const int RANK = 2;
#endif
/*.
.
.
.*/
#ifdef USE_HDF5
// Create a new file using the default property lists.
H5File file(FILE_NAME, H5F_ACC_TRUNC);
// Create the data space for the dataset.
hsize_t dims[2]; // dataset dimensions
dims[0] = NX;
dims[1] = NY;
DataSpace dataspace(RANK, dims);
// Create the dataset.
DataSet dataset = file.createDataSet(DATASET_NAME, PredType::STD_I32BE, dataspace);
#endif
Errors on build:
[ 85%] Linking CXX executable pce_eval
Undefined symbols for architecture x86_64:
"H5::H5File::H5File(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)", referenced from:
_main in pce_eval.cpp.o
"H5::H5Location::createDataSet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, H5::DataType const&, H5::DataSpace const&, H5::DSetCreatPropList const&, H5::DSetAccPropList const&, H5::LinkCreatPropList const&) const", referenced from:
_main in pce_eval.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status