From 73bf70d3324730b15f9a603692659b07a8c4071a Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Fri, 24 May 2019 23:52:38 +0200 Subject: [PATCH] Add thread library of the system by Threads::Threads instead of -pthread flag. This commit also fix "//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line". This issue was caused by missing linking of thread library in PCL_ADD_LIBRARY. --- CMakeLists.txt | 9 ++++----- cmake/pcl_targets.cmake | 15 +++------------ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e85b59046f..1e2d0e43497 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,10 +112,6 @@ if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "-Wabi -Wall -Wextra -Wno-unknown-pragmas -fno-strict-aliasing -Wno-format-extra-args -Wno-sign-compare -Wno-invalid-offsetof -Wno-conversion ${SSE_FLAGS_STR}") endif() - if(NOT ANDROID) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") - endif() - if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") endif() @@ -179,7 +175,7 @@ endif() if(CMAKE_COMPILER_IS_PATHSCALE) if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}") - set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -pthread -mp") + set(CMAKE_CXX_FLAGS "-Wno-uninitialized -zerouv -mp") endif() if("${CMAKE_SHARED_LINKER_FLAGS}" STREQUAL "") set(CMAKE_SHARED_LINKER_FLAGS "-mp") @@ -280,6 +276,9 @@ else() message(STATUS "Not found OpenMP") endif() +# Threads (required) +find_package(Threads REQUIRED) + # Eigen (required) find_package(Eigen 3.1 REQUIRED) include_directories(SYSTEM ${EIGEN_INCLUDE_DIRS}) diff --git a/cmake/pcl_targets.cmake b/cmake/pcl_targets.cmake index 5ae0f1129a7..a50d0d0998a 100644 --- a/cmake/pcl_targets.cmake +++ b/cmake/pcl_targets.cmake @@ -223,7 +223,7 @@ function(PCL_ADD_LIBRARY _name) PCL_ADD_VERSION_INFO(${_name}) target_compile_features(${_name} PUBLIC ${PCL_CXX_COMPILE_FEATURES}) # must link explicitly against boost. - target_link_libraries(${_name} ${Boost_LIBRARIES}) + target_link_libraries(${_name} ${Boost_LIBRARIES} Threads::Threads) if((UNIX AND NOT ANDROID) OR MINGW) target_link_libraries(${_name} m) endif() @@ -302,11 +302,7 @@ function(PCL_ADD_EXECUTABLE _name) endif() PCL_ADD_VERSION_INFO(${_name}) # must link explicitly against boost. - if(UNIX AND NOT ANDROID) - target_link_libraries(${_name} ${Boost_LIBRARIES} pthread m ${CLANG_LIBRARIES}) - else() - target_link_libraries(${_name} ${Boost_LIBRARIES}) - endif() + target_link_libraries(${_name} ${Boost_LIBRARIES} Threads::Threads) if(WIN32 AND MSVC) set_target_properties(${_name} PROPERTIES DEBUG_OUTPUT_NAME ${_name}${CMAKE_DEBUG_POSTFIX} @@ -384,12 +380,7 @@ macro(PCL_ADD_TEST _name _exename) #target_link_libraries(${_exename} ${GTEST_BOTH_LIBRARIES} ${PCL_ADD_TEST_LINK_WITH}) target_link_libraries(${_exename} ${PCL_ADD_TEST_LINK_WITH} ${CLANG_LIBRARIES}) - if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - target_link_libraries(${_exename} pthread) - elseif(UNIX AND NOT ANDROID) - # GTest >= 1.5 requires pthread and CMake's 2.8.4 FindGTest is broken - target_link_libraries(${_exename} pthread) - endif() + target_link_libraries(${_exename} Threads::Threads) # must link explicitly against boost only on Windows target_link_libraries(${_exename} ${Boost_LIBRARIES})