UbuntuCmake compiles Boost's pthread error

Error content:

undefined reference to symbol ‘pthread_condattr_setclock@@GLIBC_2.3.3’ error adding symbols: DSO missing from command line

CMakeLists at this point:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(cloud_viewer)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (random_sample_consensus random_sample_consensus.cpp)
target_link_libraries (random_sample_consensus ${PCL_LIBRARIES})

The reason is that Windows can locate Boost multithreading but Ubuntu cannot, so you need to manually add two places in CmakeLists:

1. Find and add the linked library directory path;

2. Link the library to our project

After changing to:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(cloud_viewer)

find_package(PCL REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
find_package(Boost REQUIRED COMPONENTS thread filesystem)
link_libraries(${Boost_LIBRARY_DIRS})
add_executable (random_sample_consensus random_sample_consensus.cpp)
target_link_libraries (random_sample_consensus ${PCL_LIBRARIES} ${Boost_LIBRARIES})

 Finally build successfully:

Guess you like

Origin blog.csdn.net/m0_46611008/article/details/124931755
Recommended