UnaNancyOwen / VelodyneCapture

VelodyneCapture is the general capture class to retrieve the laser data from Velodyne sensors using Boost.Asio and PCAP
MIT License
54 stars 21 forks source link

Linking error: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' #5

Closed Durant35 closed 7 years ago

Durant35 commented 7 years ago

[100%] Linking CXX executable VelodyneCapture /usr/bin/ld: CMakeFiles/VelodyneCapture.dir/main.cpp.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' //lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line

Durant35 commented 7 years ago
+ Maybe need to add a pthread finding `L16-17 & L88`
```cmake
cmake_minimum_required( VERSION 3.5 )

add_compile_options(-std=c++11)
#set(CMAKE_CXX_STANDARD 11) # C++11...
#set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
#set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11

# Create Project
project( sample )
add_executable( VelodyneCapture VelodyneCapture.h main.cpp )

# Set StartUp Project
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "VelodyneCapture" )

# Find Packages
# Find Package pthread
find_package(Threads REQUIRED)

# Find Package Boost
set( BOOST_ROOT "C:/Program Files/boost" )
set( Boost_USE_STATIC_LIBS ON ) # Static Link Libraries ( libboost_* )
set( Boost_USE_MULTITHREADED ON ) # Multi Thread Libraries ( *-mt-* )
set( Boost_USE_STATIC_RUNTIME OFF ) # Static Runtime Libraries ( *-s* )
find_package( Boost COMPONENTS system date_time regex )

# If Direct Capture from Sensors, VelodyneCapture are required Boost.Asio.
# Please Define HAVE_BOOST in Preprocessor.
set( HAVE_BOOST )
if( Boost_FOUND )
  set( HAVE_BOOST "-DHAVE_BOOST" )
endif()

# Find Package PCAP
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH} )
set( PCAP_DIR "C:/Program Files/WpdPack")
find_package( PCAP )

# If Capture from PCAP Files, VelodyneCapture are required PCAP.
# Please Define HAVE_PCAP in Preprocessor.
set( HAVE_PCAP )
if( PCAP_FOUND )
  set( HAVE_PCAP "-DHAVE_PCAP" )
endif()

# Find Package OpenCV
set( OpenCV_DIR "C:/Program Files/opencv/build" )
set( OpenCV_STATIC OFF )
find_package( OpenCV REQUIRED )

# Required Viz Module
if( OpenCV_FOUND )
  if( NOT "opencv_viz" IN_LIST OpenCV_LIBS )
    message( FATAL_ERROR "not found opencv_viz module." )
  endif()
endif()

if( OpenCV_STATIC AND MSVC )
  foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
    if(${flag_var} MATCHES "/MD")
      string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
    endif(${flag_var} MATCHES "/MD")
  endforeach(flag_var)
endif()

# Set Properties
if( OpenCV_FOUND AND ( PCAP_FOUND OR Boost_FOUND ) )
  # Additional Include Directories
  include_directories( ${Boost_INCLUDE_DIRS} )
  include_directories( ${PCAP_INCLUDE_DIRS} )
  include_directories( ${OpenCV_INCLUDE_DIRS} )

  # Add Definitions
  add_definitions( ${Boost_LIB_DIAGNOSTIC_DEFINITIONS} )
  add_definitions( ${HAVE_BOOST} )
  add_definitions( ${HAVE_PCAP} )

  # Additional Library Directories
  link_directories( ${Boost_LIBRARY_DIRS} )
  link_directories( ${PCAP_LIBRARY_DIRS} )
  link_directories( ${OpenCV_LIB_DIR} )

  # Additional Dependencies
  target_link_libraries( VelodyneCapture ${Boost_LIBRARIES} )
  target_link_libraries( VelodyneCapture ${PCAP_LIBRARIES} )
  target_link_libraries( VelodyneCapture ${OpenCV_LIBS})
  target_link_libraries( VelodyneCapture ${CMAKE_THREAD_LIBS_INIT})
else()
  message( WARNING "VelodyneCapture need at least either Boost or PCAP." )
endif()
UnaNancyOwen commented 7 years ago

I was commit based on your report. VelodyneCapture was able to support Linux. Thank you for your reports.