c++linuxcmakeactivemq-classicactivemq-cpp

undefined reference to symbol 'sem_close@@GLIBC_2.2.5'


I'm trying to compile a project that has ActiveMQ functions used (hence the library), however I get the following error:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libapr-1.a(proc_mutex.o): undefined reference to symbol 'sem_close@@GLIBC_2.2.5'

/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I must say that code-wise I do not have a doubt, it just works fine. This error I started to get after I formatted my computer, in which one of a few libraries required for ActiveMQ may have gone. libapr is one of them, for sure.

However, I do have this library installed on my computer. When I locate it, I can see it as w:

/usr/lib/libapr-1.a
/usr/lib/x86_64-linux-gnu/libapr-1.a
/usr/local/apr/lib/libapr-1.a

So it is there. And Also in my CMakeLists.txt file I refer it as :

set(ACTIVEMQ_CPP "/usr/local/lib/libactivemq-cpp.so")
set(ACTIVEMQ_INCLUDE_DIR "/usr/local/include/activemq-cpp-3.8.4/")

set(LIBAPR_LIB "/usr/lib/libapr-1.a")
set(LIBAPR_INCLUDE_DIR "/usr/include/apr-1")

So I do not know what causes the error. I looked at everywhere possible and still have no answer.

Any thoughts?

P.S: My complete CMakeLists.txt : cmake_minimum_required(VERSION 2.8.3) project(some_project include(FindProtobuf)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set_source_files_properties(${PROTO_SRC} ${PROTO_HEADER} PROPERTIES GENERATED TRUE)

# check c++11 / c++0x
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "-std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "-std=c++0x")
else()
    message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

set(PROTO_SRC ${PROJECT_SOURCE_DIR}/src-gen)
set(PROTO_HEADER  ${PROJECT_SOURCE_DIR}/src-gen)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  roscpp
  sensor_msgs
  std_msgs
  image_transport
)

find_package(OpenCV REQUIRED)
find_package(Protobuf REQUIRED)

catkin_package(
INCLUDE_DIRS include
LIBRARIES uwsim_imgproc filters
CATKIN_DEPENDS cv_bridge roscpp sensor_msgs std_msgs
#  DEPENDS system_lib
)

set(ACTIVEMQ_CPP "/usr/local/lib/libactivemq-cpp.so")
set(ACTIVEMQ_INCLUDE_DIR "/usr/local/include/activemq-cpp-3.8.4/")

set(LIBAPR_LIB "/usr/lib/libapr-1.a")
set(LIBAPR_INCLUDE_DIR "/usr/include/apr-1")


PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS proto/VisionData.proto)

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS} 
  ${PROTOBUF_INCLUDE_DIRS}
  ${CMAKE_CURRENT_BINARY_DIR}
  include
  ${ACTIVEMQ_INCLUDE_DIR}
  ${LIBAPR_INCLUDE_DIR}
)

link_directories( 
  ${OpenCV_LINK_DIRS}
)

add_library(filters
      src/HorizonDetector.cpp
        src/ActivemqSender.cpp
)

add_executable(cameraSubscriber src/main.cpp ${PROTO_SRCS} ${PROTO_HDRS})

add_dependencies(cameraSubscriber ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(filters
   ${OpenCV_LIBRARIES}
)

target_link_libraries(cameraSubscriber
   ${catkin_LIBRARIES}
   ${OpenCV_LIBRARIES}
   ${PROTOBUF_LIBRARIES}
   ${ACTIVEMQCPP_LIBRARIES}
   filters
   ${ACTIVEMQ_CPP}
   ${LIBAPR_LIB}
 )

Solution

  • Okay, thanks to @Tsyvarev , found the problem.

    It lies within the linking order which is specified in CMakeLists.txt file. It should have the following order, in which -lpthread comes before libapr-1.a

    target_link_libraries(cameraSubscriber
       ${catkin_LIBRARIES}
       ${OpenCV_LIBRARIES}
       ${LIBAPR_LIB}
       ${PROTOBUF_LIBRARIES}
       ${ACTIVEMQCPP_LIBRARIES}
       filters
       ${ACTIVEMQ_CPP}
    
     )