1

I am trying to compile a simple program to read a HDF5 file. The code compiles correctly with h5c++. However I need a cmakelists.txt for the same

readdata.cpp

#include <iostream>
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
    using namespace H5;
#endif
const H5std_string FILE_NAME( "testfile.h5" );

int main (void)
{
    H5File openFile( FILE_NAME, H5F_ACC_RDONLY );
}

I tried a cmakelists for it but it didnt work. It gave "not defined errors"

readdata.cpp:(.text+0x1d): undefined reference to `H5::FileAccPropList::DEFAULT'
readdata.cpp:(.text+0x24): undefined reference to `H5::FileCreatPropList::DEFAULT'
readdata.cpp:(.text+0x38): undefined reference to `H5check_version'
readdata.cpp:(.text+0x54): undefined reference to `H5::H5File::H5File(std::__cxx11::basic_string<char,     std::char_traits<char>, std::allocator<char> > const&, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)'
readdata.cpp:(.text+0x60): undefined reference to `H5::H5File::~H5File()'

CMakelists.txt

cmake_minimum_required(VERSION 3.1.0) 
PROJECT (readhdf5)

find_package(HDF5 REQUIRED)
include_directories(${HDF5_INCLUDE_DIRS})

add_executable( readdata readdata.cpp )

target_link_libraries( readdata ${HDF5_CXX_LIBRARIES} ${HDF5_LIBRARIES})

If i put the HDF5_CXX_LIBRARIES and HDF5_LIBRARIES manually the it works.

target_link_libraries( readdata libhdf5.so libhdf5_cpp.so)

So it is not able to read $HDF5_CXX_LIBRARIES and $HDF5_LIBRARIES.How can I fix this?

1
  • Prefer target_include_directories Commented Aug 7, 2019 at 18:42

1 Answer 1

6

The code you attempt to compile depends on the HDF5 C++ bindings, which are not searched for by CMake's HDF5 module by default. Explicitly add the binding to the find_package command:

find_package(HDF5 REQUIRED COMPONENTS C CXX)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.