2016-11-29 225 views
0

我試圖編譯具有使用ActiveMQ的功能(因此庫)的一個項目,但我得到以下錯誤:未定義的參考符號「sem_close @@ GLIBC_2.2.5」

/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 '[email protected]@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") 

所以我不知道是什麼導致了錯誤。我看到了可能的任何地方,仍然沒有答案。

有什麼想法?

PS:我的完整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} 
) 
+0

'從命令行丟失的DSO很容易被google搜索到,意味着鏈接庫的順序*不正確*。你的'libapr-1.a'庫應該在**'-lpthread'之前**鏈接列表中。 – Tsyvarev

+0

我的'CMakeLists.txt'中沒有'-lpthread',因此我不知道這是什麼順序。也許我可以添加完整的'CMakeLists.txt'。 –

回答

0

好了,感謝@Tsyvarev,發現問題

它位於CMakeLists.txt文件中指定的鏈接順序內,它應該具有以下順序,其中-lpthread在之前

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

)