1

我正在尝试使用外部库构建项目,但系统一直认为它需要使用损坏的 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,因为符号链接已损坏。那么如何让它查看该库的另一个地址呢?任何帮助消除此错误将不胜感激

4

1 回答 1

2

对于将 cmake 项目与 hdf5 链接,我建议使用find_packagecmake 的功能。

包括行

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
于 2017-06-22T09:41:33.040 回答