0

I'm working in a ROS project using WebRTC as well.

My problem is when I try to build my project, I get this:

/usr/bin/ld: /home/carlos/Documentos/ROS_WebRTC/catkin_ws/src/libwebrtc/out/lib/libwebrtc.a(thread_pthread.o): undefined symbol reference 'pthread_rwlock_wrlock@@GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line

Searching in other posts with the similar problem, I've come to a conclusion I have to add CMAKE FLAG "-pthread" to g++.

Using VERBOSE=1 with catkin_make I realize that, in fact, the .cc file which causes the problem need that flag. But I don't know how add it.

I have tried with set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpthread") but it doesn't fix anything.

This is my CMakeFiles.txt:

cmake_minimum_required(VERSION 2.8.3)
project(webrtcbridge)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  rospy
  genmsg
)

find_package(LibWebRTC REQUIRED)

catkin_package()

include_directories(
 include ${catkin_INCLUDE_DIRS}
)

include_directories(
include ${LIBWEBRTC_USE_FILE}
)

add_executable(webrtcbridge_node src/webrtcbridge_node.cc)

target_link_libraries (webrtcbridge_node ${catkin_LIBRARIES})
target_link_libraries (webrtcbridge_node ${LIBWEBRTC_LIBRARIES})

And this is a piece of verbose got executing catkin_make:

/usr/bin/c++ CMakeFiles/webrtcbridge_node.dir/src/webrtcbridge_node.cc.o -o /home/carlos/Documentos/ROS_WebRTC/catkin_ws/devel/lib/webrtcbridge/webrtcbridge_node -rdynamic /opt/ros/kinetic/lib/libroscpp.so -lboost_signals -lboost_filesystem /opt/ros/kinetic/lib/librosconsole.so /opt/ros/kinetic/lib/librosconsole_log4cxx.so /opt/ros/kinetic/lib/librosconsole_backend_interface.so -llog4cxx -lboost_regex /opt/ros/kinetic/lib/libxmlrpcpp.so /opt/ros/kinetic/lib/libroscpp_serialization.so /opt/ros/kinetic/lib/librostime.so /opt/ros/kinetic/lib/libcpp_common.so -lboost_system -lboost_thread -lboost_chrono -lboost_date_time -lboost_atomic -lpthread -lconsole_bridge /home/carlos/Documentos/ROS_WebRTC/catkin_ws/src/libwebrtc/out/lib/libwebrtc.a -lSM -lICE -lX11 -lXext -ldl -lrt -Wl **"here should be -pthread I think"**,-rpath,/opt/ros/kinetic/lib

Any idea about set "pthread" at the end?

Mark Booth
  • 7,605
  • 2
  • 68
  • 92
CharlieHollow
  • 441
  • 1
  • 6
  • 12
  • Have you tried `target_link_libraries(webrtcbridge_node pthread)`? The verbose text you quoted has `lpthread` in it already, so your issue may not be that. – hnefatl Jul 24 '17 at 13:27
  • Possible duplicate of [cmake and libpthread](https://stackoverflow.com/questions/1620918/cmake-and-libpthread) – hnefatl Jul 24 '17 at 13:36
  • Yeah, I tried it, and the problem persists @hnefatl. – CharlieHollow Jul 24 '17 at 18:07

1 Answers1

0

"DSO missing" - DSO is a Dynamic Shared Object. You need to link the threads library to your executable.

Try this:

find_package(Threads)

...

target_link_libraries(webrtcbridge_node ${CMAKE_THREAD_LIBS_INIT})
CK.
  • 312
  • 3
  • 13
  • These solution was one of the different options I saw in another posts. However, it didn't fix my problem, it has to be anything else. – CharlieHollow Jul 24 '17 at 18:10
  • Although using `link_directories()` is not recommended, can you try: `link_directories(/usr/lib/x86_64-linux-gnu)` and `target_link_libraries(webrtcbridge_node -lpthread)`? – CK. Jul 25 '17 at 20:56