【问题标题】:Can't make cgal and hdf5 work together不能让 cgal 和 hdf5 一起工作
【发布时间】:2014-12-29 12:21:25
【问题描述】:

我正在使用these 步骤(第二个源代码位置的第 42 行)。但是,我读/写扩展名为 .h5 的文件,其中代码肯定需要这个标志:-lhdf5

为了编译 hdf5 的函数,我会这样做:

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

注意标志必须放置在编译命令的末尾,如this answer中所述。

由于评论,我更新了我的问题。

所以,我修改了 CMakeLists.txt,我改变的是这部分:

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

但是,当我执行 make 时,似乎找不到 hdf5。


编辑

在马克的建议下,我得到了:

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

我认为这就是问题所在(也请参阅我链接的答案)。 hdf5 的链接器标志不在末尾。

最后怎么写?也许我用错了set()


编辑 - 解决方案

这是有效的 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})

【问题讨论】:

  • 你不需要链接器标志而不是编译器标志吗?
  • 嗯,我想到了这一点,但我知道为了获得 C++11 支持,我们必须按照我现在的方式进行。所以我认为hdf5应该通过同样的方式。但是现在我有一个问题,hdf的标志是什么? @juanchopanza
  • 我不是指 c++11 glag(它必须是编译器标志)。我的意思是图书馆标志。 -lname 表示“链接库libnamecmake 必须有不同的变量。
  • 我想我得看看这里:stackoverflow.com/questions/6077414/…
  • @juanchopanza,还是什么都没有。

标签: c++ makefile shared-libraries hdf5 cgal


【解决方案1】:

我同时使用 CGAL 和 HDF5。这是我的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)

在 CMakeLists.txt 的前面,有:

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}")

【讨论】:

  • 当我使用 cmake 时,我收到错误 `set_target_properties called with wrong number of arguments.。此外,您发布的某些行对我不起作用,因为它们似乎是针对 voronoi 的某个项目。所以,我正在编辑我的问题,以便人们可以看到我的 CMakeLists.txt
  • 也许我也需要设置一些东西,比如你所做的编辑?请检查我的 CMakeLists.txt。
  • 我已更改名称以匹配您的名称。
  • 至于 set_target_properties,您可以去掉所有这些行并用 set (HDF5_libraries ${HDF5_hdf5_LIBRARY} ${HDF5_hdf5_cpp_LIBRARY}) 替换它们
  • 好吧,我必须摆脱错误,因为错误导致无法创建makefile。所以,我必须添加你拥有的第二段代码,然后在它下面添加第一段代码?此外,我应该在 CMakeLists.txt 中的某个位置吗?
猜你喜欢
  • 2012-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-20
  • 1970-01-01
  • 2017-01-15
  • 2019-06-21
  • 1970-01-01
相关资源
最近更新 更多