【问题标题】:Undefined reference on compiling with lib-urcu with CMake使用 CMake 编译 lib-urcu 的未定义参考
【发布时间】:2017-05-23 15:19:17
【问题描述】:

我将不胜感激有关如何解决以下问题的任何建议:

CMakeFiles/es.dir/epollsock.cpp.o: In function `cds_lfht_new':
/usr/include/urcu/rculfhash.h:167: undefined reference to `_cds_lfht_new'
CMakeFiles/es.dir/epollsock.cpp.o: In function `WordCounterRCU::removeHashTable()':
~/WordCounterRCU.hpp:37: undefined reference to `cds_lfht_destroy'
CMakeFiles/es.dir/epollmsg.cpp.o: In function `cds_lfht_new':
/usr/include/urcu/rculfhash.h:167: undefined reference to `_cds_lfht_new'
CMakeFiles/es.dir/epollmsg.cpp.o: In function `WordCounterRCU::addWord(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
~/WordCounterRCU.hpp:69: undefined reference to `cds_lfht_add_unique'
CMakeFiles/es.dir/epollmsg.cpp.o: In function `WordCounterRCU::getCount()':
~/WordCounterRCU.hpp:96: undefined reference to `cds_lfht_count_nodes'

我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.7)
project(effective_server)

set(CMAKE_CXX_STANDARD 11)

<< part with liburcu >>

find_package (Threads)

set(SOURCE_FILES ...)
add_executable(effective_server ${SOURCE_FILES})

target_link_libraries (effective_server ${CMAKE_THREAD_LIBS_INIT} -lurcu)

if (LIBURCU_FOUND)
    include_directories( ${LIBURCU_INCLUDE_DIR} )
    target_link_libraries(effective_server ${LIBURCU_LIBRARY})
endif(LIBURCU_FOUND)

find_package( ZLIB REQUIRED )
if ( ZLIB_FOUND )
    include_directories( ${ZLIB_INCLUDE_DIRS} )
    target_link_libraries( effective_server ${ZLIB_LIBRARIES} )
endif( ZLIB_FOUND )

带有liburcu的部分是从https://github.com/markusa/netsniff-ng_filter/tree/master/src/cmake/modules复制过来的。

我检查了 LIBURCU_INCLUDE_DIR 和 LIBURCU_LIBRARY,它们似乎是正确的。

谢谢!

【问题讨论】:

  • 根据回答,您只是忘记链接urcu-cds。顺便说一句,target_link_libraries 可以省略 -l 标志,CMake 会自动添加它:target_link_libraries (effective_server ${CMAKE_THREAD_LIBS_INIT} urcu)
  • @Tsyvarev,谢谢,不知道:)

标签: c++ cmake rcu


【解决方案1】:

这是关于缺少链接器标志 -lurcu-cds。它应该是: target_link_libraries (effective_server ${CMAKE_THREAD_LIBS_INIT} -lurcu -lurcu-cds)

【讨论】:

    猜你喜欢
    • 2017-10-13
    • 1970-01-01
    • 2014-07-25
    • 2022-10-15
    • 2015-09-14
    • 1970-01-01
    • 2023-03-13
    • 2015-06-25
    • 2014-09-20
    相关资源
    最近更新 更多