CMake undefined reference to symbol ‘pthread_condattr_setclock@@GLIBC_2.3.3‘

用CMake编译项目的时候报错:
undefined reference to symbol ‘pthread_condattr_setclock@@GLIBC_2.3.3’
error adding symbols: DSO missing from command line

找了半天发现了stackoverflow上面的一个答案
https://stackoverflow.com/questions/19901934/libpthread-so-0-error-adding-symbols-dso-missing-from-command-line
CMake undefined reference to symbol ‘pthread_condattr_setclock@@GLIBC_2.3.3‘_第1张图片
大概意思就是所需的库里如果有需要的引用库,应把引用的库放在前面,因此这里在target_link_libraries()时根据所需应增加引用库,我的比较特殊,重复增加了一个才可以编译通过:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(lidar_demo)
find_package(OpenCV REQUIRED)
set(lib_DIR "~/tools/Neuvition_tools/neusdk-x86_64-2.5.5/sdk/lib")
set(include_DIR "~/tools/Neuvition_tools/neusdk-x86_64-2.5.5/sdk/include")
include_directories(${OpenCV_INCLUDE_DIRS} "~/tools/Neuvition_tools/neusdk-x86_64-2.5.5/sdk/include")
link_directories(${OpenCV_LIBRARY_DIRS} "~/tools/Neuvition_tools/neusdk-x86_64-2.5.5/sdk/lib")
add_executable (lidar_demo main.cpp)
target_link_libraries (lidar_demo pthread curl uuid libpthread.so pthread libneusdk.a ${OpenCV_LIBS})

同时这里也增加了libpthread.so pthread,经测试发现如果不增加libpthread.so也是不能通过编译,是因为linux系统有时候默认找不到pthread

你可能感兴趣的:(自动驾驶,ubuntu,opencv,linux)