H5std_string not recognized on OSX with CMake

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)
    message(STATUS "HDF5 version: ${HDF5_VERSION}")
    message(STATUS "HDF5 include dir: ${HDF5_INCLUDE_DIRS}")
    message(STATUS "HDF5 CXX lib: ${HDF5_CXX_LIBRARIES}")
    target_link_libraries(pce_eval ${HDF5_CXX_LIBRARIES})
    # Download HDF5 library and define hdf5_local TODO
    # ...

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;
#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);

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

Here is how we open a file…emh is a custom error message handler, note we only read the file so we use H5F_ACC_RDONLY hope that helps

H5File * H5Utils::openH5File(H5std_string inFile, ErrorMsgHandler *emh) {
    if (emh == nullptr) {
        cerr<<"emh is nullptr!"<<endl;
        return nullptr;

    H5File * h5File = nullptr;
    try {
        h5File = new H5File(inFile.c_str(), H5F_ACC_RDONLY);
        emh->setMsg(0, "File is open: " + inFile);
    } catch (FileIException e) {
        emh->setMsg(-1, "File failed to open: " + inFile + " exception: " + e.getDetailMsg());
    return h5File;


First place to look would be to verify that your HDF5 libraries have been compiled with the same C++ standard as the code from which you are trying to use them. If I had to guess it looks like your code is compiled with C++11 (at least) and the HDF5 library was compiled with C++98.

What makes me suspicious is that CMake picks up your Anaconda installation.

-- 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

Are you sure that’s a 64-bit version of Anaconda?

Undefined symbols for architecture x86_64: ...