0

I am using these steps (line 42 in the 2nd sourcecode place). However, I reading/writing to files with .h5 extension, where the code needs surely this flag: -lhdf5.

In order to compile the functions for hdf5, I would do something like this:

g++ -std=c++0x main.cpp -lhdf5

Notice that the flag must be placed at the end of the compilation command, as stated in this answer.

I updated my question, due to a comment.

So, I modified the CMakeLists.txt and what I changed was this part:

add_definitions(${CMAKE_CXX_FLAGS} "-std=c++0x")
set(CMAKE_EXE_LINKER_FLAGS "-lhdf5 -lhdf5_hl -lhdf5_cpp")

However, when I execute make, it seems that hdf5 is not found.


EDIT

With Marc's suggestion, I got:

Linking CXX executable exe
/usr/bin/cmake -E cmake_link_script CMakeFiles/exe.dir/link.txt --verbose=1
/usr/bin/c++    -frounding-math -O3 -DNDEBUG  -lhdf5 -lhdf5_hl -lhdf5_cpp CMakeFiles/exe.dir/match.cpp.o  -o exe -rdynamic -L/home/samaras/code/CGAL-4.3/lib -L/usr/local/lib -lmpfr -lgmp /home/samaras/code/CGAL-4.3/lib/libCGAL.so -lboost_thread-mt -lpthread /usr/local/lib/libboost_system.so /home/samaras/code/CGAL-4.3/lib/libCGAL.so -lboost_thread-mt -lpthread /usr/local/lib/libboost_system.so -Wl,-rpath,/home/samaras/code/CGAL-4.3/lib:/usr/local/lib

and here is the problem, I think (see the answer I linked too). The linker flag of hdf5 is NOT at the end.

How to put it at the end? Maybe I am using the wrong set()?


EDIT - solution

Here is the working CMakeLists.txt:

# Created by the script cgal_create_cmake_script_with_options
# This is the CMake script for compiling a set of CGAL applications.

project( exe )


cmake_minimum_required(VERSION 2.6.2)
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6)
  if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3)
    cmake_policy(VERSION 2.8.4)
  else()
    cmake_policy(VERSION 2.6)
  endif()
endif()

set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true )

if ( COMMAND cmake_policy )

  cmake_policy( SET CMP0003 NEW )  

endif()

# CGAL and its components
add_definitions(${CMAKE_CXX_FLAGS} "-std=c++0x")
find_package( CGAL QUIET COMPONENTS  )

if ( NOT CGAL_FOUND )

  message(STATUS "This project requires the CGAL library, and will not be compiled.")
  return()  

endif()

# include helper file
include( ${CGAL_USE_FILE} )

find_package            (CGAL)
include                 (${CGAL_USE_FILE})
add_definitions         (${CGAL_CXX_FLAGS_INIT})
include_directories     (${CGAL_INCLUDE_DIRS})
set                     (libraries ${libraries} ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES})
set                     (CMAKE_EXE_LINKER_FLAGS "-dynamic ${CMAKE_EXE_LINKER_FLAGS}")

find_package                (HDF5 QUIET COMPONENTS CXX)

if                          (HDF5_FOUND)

  include_directories       (SYSTEM ${HDF5_CXX_INCLUDE_DIR})

  set (HDF5_libraries ${HDF5_hdf5_LIBRARY} ${HDF5_hdf5_cpp_LIBRARY})
  set                       (HDF5_libraries     hdf5 hdf5_cpp)

endif                       (HDF5_FOUND)


# Boost and its components
find_package( Boost REQUIRED )

if ( NOT Boost_FOUND )

  message(STATUS "This project requires the Boost library, and will not be compiled.")

  return()  

endif()

# include for local directory

# include for local package


# Creating entries for target: exe
# ############################

add_executable( exe  match.cpp )

add_to_cached_list( CGAL_EXECUTABLE_TARGETS exe )

# Link the executable to CGAL and third-party libraries
target_link_libraries(exe   ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${libraries} ${HDF5_libraries})
Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • Don't you need linker flags rather than compiler ones? – juanchopanza Nov 02 '14 at 21:04
  • Well I thought of that, but I know that in order to have C++11 support, we have to do it the way I have it now. So I thought that the hdf5 should go through the same way. But now I have a question, what kind of flag is the one of hdf? @juanchopanza – gsamaras Nov 02 '14 at 21:06
  • I don't mean the c++11 glag (that has to be a compiler flag). I mean the library flags. `-lname` means "link library `libname`. `cmake` must have a different variable for those. – juanchopanza Nov 02 '14 at 21:08
  • I guess I will have to look here then: http://stackoverflow.com/questions/6077414/cmake-how-to-set-the-ldflags-in-cmakelists-txt – gsamaras Nov 02 '14 at 21:13
  • @juanchopanza, still nothing. – gsamaras Nov 02 '14 at 21:20
  • cmake comes with a FindHDF5.cmake file, so you should be able to do things the cmake way. By the way, `make VERBOSE=1` helps see what is going on. – Marc Glisse Nov 02 '14 at 21:59
  • @MarcGlisse, should I change approach you mean? The verbose helped, see my edit! – gsamaras Nov 02 '14 at 22:22
  • The verbose helped to see what's up, not solving the problem! – gsamaras Nov 04 '14 at 01:30

1 Answers1

0

I use CGAL and HDF5 together. Here's the relevant bit from my CMakeLists.txt:

find_package                (HDF5 QUIET COMPONENTS CXX)

if                          (HDF5_FOUND)

  include_directories       (SYSTEM ${HDF5_CXX_INCLUDE_DIR})

  add_library               (hdf5 STATIC IMPORTED)
  set_target_properties     (hdf5 PROPERTIES IMPORTED_LOCATION ${HDF5_hdf5_LIBRARY})
  add_library               (hdf5_cpp STATIC IMPORTED)
  set_target_properties     (hdf5_cpp PROPERTIES IMPORTED_LOCATION ${HDF5_hdf5_cpp_LIBRARY})
  set                       (HDF5_libraries     hdf5 hdf5_cpp)

  add_executable            (exe match.cpp)
  target_link_libraries     (exe ${libraries} ${HDF5_libraries})
endif                       (HDF5_FOUND)

Earlier in CMakeLists.txt, there is:

find_package            (CGAL)
include                 (${CGAL_USE_FILE})
add_definitions         (${CGAL_CXX_FLAGS_INIT})
include_directories     (${CGAL_INCLUDE_DIRS})
set                     (libraries ${libraries} ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES})
set                     (CMAKE_EXE_LINKER_FLAGS "-dynamic ${CMAKE_EXE_LINKER_FLAGS}")
foxcub
  • 2,517
  • 2
  • 27
  • 27
  • I get an error `set_target_properties called with incorrect number of arguments., when I use cmake. Also, some of the lines you posted are not going to work for me, since they appear to be for a certain project with voronoi. So, I am editing my question so that one can see my CMakeLists.txt – gsamaras Nov 04 '14 at 18:52
  • Maybe I need to set something too, like the edit you make? Please check my CMakeLists.txt. – gsamaras Nov 04 '14 at 19:05
  • I've changed the names to match yours. – foxcub Nov 04 '14 at 19:09
  • As for set_target_properties, you could get rid of all of those lines and replace them with set (HDF5_libraries ${HDF5_hdf5_LIBRARY} ${HDF5_hdf5_cpp_LIBRARY}) – foxcub Nov 04 '14 at 19:10
  • Well I must get rid of the error, because the error causes the non creation of the makefile. So, I have to add the 2nd piece of code you have and then, below it the first? Moreover, should I put somewhere exactly in the CMakeLists.txt? – gsamaras Nov 04 '14 at 19:14
  • Yes. And I suspect removing the add_library and set_target_properties lines (and replacing them with the line from my previous comment) will fix the error. – foxcub Nov 04 '14 at 21:14
  • I will update my question with the CMakeLists.txt that actually worked (pretty much what you told me, but had to change something). THANK YOU. I would like you to upvote you twice (so I will see your history to find something nice). Thank you again! :D – gsamaras Nov 04 '14 at 21:27