Cmake error 'libmylib.so undefined reference to 'pthread_create'
I am trying to use an external library (libmylib.so) in my package ROS. My problem is that this library required pthread to compile.
I have already use pthread in my work. So, I add pthread rt in the targetlinklibraries :
target_link_libraries(mypackage
${catkin_LIBRARIES}
${mylib}
pthread rt)
Without using CMake it works fine but using Cmake I foud two errors:
${PATH_TO_MY_LIB}/libmylib.so: undefined reference to 'pthread_create'
${PATH_TO_MY_LIB}/libmylib.so: undefined reference to 'pthread_cancel'
I founded the same error with these others tests :
Test 1:
add_definietions("-std=c++11 -Wall -g -lpthread")
list(APPEND CMAKE_CXX_FLAGS "-lpthread"
Test 2:
find(package(Threads REQUIRED)
target_link_libraries( mypackage
${catkin_LIBRARIES}
${mylib}
${CMAKE_THREAD_LIBS_INIT} )
Test 3:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
Test 4:
set(CMAKE_LINKER_FLAGS "-pthread" CACHE STRING "Linker Flags" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS}" CACHE STRING "" FORCE)
Test 5:
set_target_properties(mypackage PROPERTIES COMPILE_FLAGS -pthread LINK_FLAGS -pthread)
I am open to any suggestion ! Thank you
Asked by Merle on 2017-11-13 08:07:22 UTC
Comments
maybe this will be helpful: https://answers.ros.org/question/274451/how-to-utilize-so-file-in-cmakeliststxt/? Also, once you add libraries in the project's CMakeLists.txt, delete the following before running catkin_make: (1)devel directory (2) build directory (3)"global" CMakeLists.txt
Asked by BuilderMike on 2017-11-14 07:47:47 UTC