未定义的符号引用 'sem_close@@GLIBC_2.2.5'

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

我正在尝试编译一个使用了 ActiveMQ 函数的项目(因此使用了库),但是我收到以下错误:

/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

我必须说在代码方面我没有怀疑,它工作正常。我在格式化计算机后开始出现此错误,其中 ActiveMQ 所需的几个库之一可能已经消失。 libapr 当然是其中之一。

但是,我的电脑上确实安装了这个库。当我找到它时,我可以看到它是 w:

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

原来如此。而且在我的 CMakeLists.txt 文件中,我将其称为:

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")

所以我不知道是什么原因导致的错误。我到处都看了,还是没有答案。

有什么想法吗?

P.S: 我的完整 CMakeLists.txt : cmake_minimum_required(版本 2.8.3) 项目(some_project 包括(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}
 )

好的,感谢@Tsyvarev ,找到问题了

它位于 CMakeLists.txt 文件中指定的链接顺序内。它应该具有以下顺序,其中 -lpthreadlibapr-1.a

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

 )