我正在尝试链接到ros节点的boost库,在连接中我找到了以下链接:" How to include external library (boost) into CLion C++ project with CMake?"和" How to link C++ program with Boost using CMake"和" problem building in groovy with catkin and boost"。
因此,我创建了我的CMakelists.txt,如下所示,需要使用OpenCV和Boost:
cmake_minimum_required(VERSION 2.8.3)
project(image_listener_rosbag)
#set(Boost_USE_STATIC_LIBS OFF)
#set(Boost_USE_MULTITHREADED ON)
#set(Boost_USE_STATIC_RUNTIME OFF)
## Find catkin macros and libraries
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
message_generation
roscpp
sensor_msgs
std_msgs
)
add_message_files(
FILES
)
generate_messages(
DEPENDENCIES
std_msgs
sensor_msgs
)
catkin_package(
CATKIN_DEPENDS message_runtime
)
find_package(catkin REQUIRED)
find_package(OpenCV REQUIRED)
find_package( Boost REQUIRED COMPONENTS serialization archive ) # is this correct?
# The components included are chosen because I need to use the following usings:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/split_free.hpp>
include_directories(
${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
)
link_directories(${Boost_LIBRARY_DIR})
add_library(image_listener_rosbag src/image_listener.cpp)
add_dependencies(image_listener_rosbag ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_executable(image_listener_rosbag_node src/image_listener.cpp)
target_link_libraries(image_listener_rosbag_node ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} ${Boost_LIBRARIES})#
当我尝试构建它时,突然出现另一个依赖于PCL的程序包崩溃:
-- Configuring incomplete, errors occurred!
See also "/home/johann/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/johann/catkin_ws/build/CMakeFiles/CMakeError.log".
make: *** [cmake_check_build_system] Error 1
调查CMakeError.log
抱怨未找到pthread_create
。崩溃的PCL软件包没有提到除了PCL内部的提升。我应该如上所述在故障包中明确添加提升吗? 尝试:将有关上述提升的信息添加到PCL节点,我得到了引用丢失的pthread_create
的相同错误日志。
作为一个测试,如果从上面的代码中删除所有的boost引用,我已尝试以多种方式编辑上面的代码,这两个包都是构建并运行没有问题。
如果我删除find_package(Boost ...
,我会收到很多问题:未定义的引用boost :: archive :: detail :: basic_oarchive :: ~basic_oarchive()`但是PCL节点编译没问题。< / p>
问题:我是否正确添加了boost和库? 如果在包含PCL的另一个包中需要特殊引用时会出现问题吗?
系统:作为参考,我使用ros indigo full实现它,包含opencv(2.4)和pcl(看起来像1.54库),一切都在Ubuntu 14.04上。
附加
这个问题,&#34; PCL install links directly to boost installation directory somehow&#34;,似乎有一些相同的问题,但我们还没能转移建议。
PCL节点
以下节点是在上面添加了增强包含时出现错误的节点。
cmake_minimum_required(VERSION 2.8.3)
project(pointcloudlistener)
find_package(PCL REQUIRED)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
PCL
pcl_ros
roscpp
sensor_msgs
std_msgs
)
add_message_files(
FILES
)
generate_messages(
DEPENDENCIES
std_msgs
sensor_msgs
)
catkin_package(
CATKIN_DEPENDS message_runtime
)
find_package(catkin REQUIRED)
find_package(OpenCV REQUIRED)
find_package(PCL REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS})
link_directories(
${PCL_LIBRARY_DIRS}
)
add_library(pointcloudlistener src/pcl_listener.cpp src/matPclConverter.cpp src/Image_Safety.cpp)
add_dependencies(pointcloudlistener ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_executable(pointcloudlistener_node src/pcl_listener.cpp src/matPclConverter.cpp src/Image_Safety.cpp)
target_link_libraries(pointcloudlistener_node ${OpenCV_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES})