3

I am trying to link to the boost libraries for a ros node, in connection I found the following links: "How to include external library (boost) into CLion C++ project with CMake?" and "How to link C++ program with Boost using CMake" and "problem building in groovy with catkin and boost".

As a result I create my CMakelists.txt as follows which needs to use OpenCV and 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})#

When I try to build it suddenly another package relying on PCL crashes with:

 -- 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

Looking into the CMakeError.log Complains about not finding pthread_create. The PCL package that crashes has no reference to boost other than what PCL has inside. Should I add boost explicitly in the failing package as above? Tried: adding the information about boost from above to the PCL node, I get the same error log referencing the missing pthread_create.

As a test I have tried editing the code above in several ways if remove all the boost references from the code above, both packages are build and runs with no issue.

If I remove find_package(Boost ... I receive a lot of issues like: undefined reference to boost::archive::detail::basic_oarchive::~basic_oarchive()` But the PCL node compiles fine with no issue.

Question: Am I adding boost correctly and the libraries? If so is there some issue when including PCL in another package that you need a special reference?

System: For reference I am implementing it using ros indigo full, with the included opencv(2.4) and pcl(looks like 1.54 libraries), everything is on Ubuntu 14.04.

Extra

This question, "PCL install links directly to boost installation directory somehow", seems to have some of the same issues I have however not been able to transfer the suggestions yet.

PCL node

The below node is the one exhibiting the error when the boost includes are added above.

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})
Community
  • 1
  • 1
JTIM
  • 2,774
  • 1
  • 34
  • 74
  • your CMakeLists doesen't mention PCL in anyway ? so which PCL node ? – Vtik Jan 31 '17 at 09:25
  • @Vtik no it does not, the pcl node is another node which works completely. However when I add boost to the nose described above the pcl node fails. That is why I draw that into the question. Therefore firstly my question is if the above is the correct way to add boost, to try and limit the issue size. – JTIM Jan 31 '17 at 12:55
  • 1
    well, looks like PCL is nevertheless linked to the issue and it won't help without posting the full CMakeLists. without it, we wouldn't be able to reproduce the error, so a bit lengthy is worth it ... – Vtik Jan 31 '17 at 13:19
  • @Vtik Sorry thank you for looking at the question. I have now added the requested CMakelists.txt – JTIM Jan 31 '17 at 13:57
  • If it is really pthread_create error, add to your `target_link_libraries` `pthread` and `rt`, but it will be nice to see some more lines in your output before the error, and some lines from your log – avtomaton Feb 02 '17 at 15:05
  • 3
    The comment above, but instead of hardcoding platform-dependent threading libraries, use `find_package(Threads REQUIRED); target_link_libraries(... ${Threads_LIBRARIES})`. Also, remove that extra `find_package(catkin REQUIRED)`! – at-2500 Mar 13 '17 at 09:39

0 Answers0