UbuntuCmake编译Boost的pthread错误

报错内容:

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

此时的CMakeLists:

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

其原因是windows可定位Boost多线程而Ubuntu则不行,故而需要手动在CmakeLists中添加两处:

1.查找并添加链接的库目录路径;

2.链接库到我们的工程

更改后为:

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

 最终成功构建:

UbuntuCmake编译Boost的pthread错误_第1张图片

你可能感兴趣的:(c++,开发语言,ubuntu)