注册。使用CMake将外部库链接到项目

时间:2017-06-21 15:37:46

标签: cmake hdf5 ros catkin

我正在尝试使用外部库构建项目,但系统一直认为它需要使用usr / lib中的库,这个库已被破坏。我希望改为使用在地址中构建的库:/home/CMake-hdf5-1.8.18/build/HDF5-1.8.18-Linux/HDF_Group/HDF5/1.8.18/include。这是CMakeLists.txt。我想要的解决方案是#Add hdf5库下的两行。

cmake_minimum_required(VERSION 2.8.3)
project(scan_to_cloud_converter)

# List C++ dependencies on ros packages
set( ROS_CXX_DEPENDENCIES
  roscpp
  pcl_ros
  pcl_conversions)

# Find catkin and all required ROS components
find_package(catkin REQUIRED COMPONENTS ${ROS_CXX_DEPENDENCIES})
find_package(PCL REQUIRED QUIET)

# Set include directories
include_directories(include ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})

# Declare info that other packages need to import library generated here
catkin_package( )

#Create node
add_executable( scan_to_cloud_converter_node
src/scan_to_cloud_converter_node.cpp
src/scan_to_cloud_converter.cpp )

#Add hdf5 library
link_directories(/home/CMake-hdf5-1.8.18/build/HDF5-1.8.18-Linux/HDF_Group/HDF5/1.8.18/include)
target_link_libraries(scan_to_cloud_converter_node libhdf5)

# No need to link against pcl (using header only libraries)
target_link_libraries( scan_to_cloud_converter_node ${catkin_LIBRARIES})

add_dependencies(scan_to_cloud_converter_node ${catkin_EXPORTED_TARGETS})

#Install node
install(TARGETS scan_to_cloud_converter_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )

这是我仍然会收到的错误消息:

make[2]: *** No rule to make target '/usr/lib/x86_64-linux-gnu/hdf5/serial/lib/libhdf5.so', needed by '/home/catkin_ws/devel/lib/scan_to_cloud_converter/scan_to_cloud_converter_node'.  Stop.

我已经对这个错误进行了研究,因为它仍然在查看/ usr / lib,并且没有库libhdf5.so,因为符号链接被破坏了。那么如何让它来查看该库的其他地址呢?任何帮助删除此错误将非常感激

1 个答案:

答案 0 :(得分:1)

为了将cmake项目与hdf5相关联,我建议使用cmake的find_package功能。

加入

find_package(HDF5)
CMakeLists.txt中的

然后,您可以使用target_link_libraries(your_lib ${HDF5_C_LIBRARIES})进行适当的链接。包含目录存储在${HDF5_INCLUDE_DIRS}

现在,就您选择特定HDF5位置的问题而言,发出命令

export HDF5_ROOT=/home/CMake-hdf5-1.8.18/build/HDF5-1.8.18-Linux/HDF_Group/HD‌​F5/1.8.18

发布cmake之前。你需要有一个清晰的缓存来实现这个目的:

rm -r CMakeCache.txt CMakeFiles