使用外部库poco CMake未定义的符号

时间:2015-08-30 00:00:16

标签: c++ macos cmake poco clion

使用poco库构建项目时,出现以下错误:

    /Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/alan/Library/Caches/clion11/cmake/generated/12b7e3f2/12b7e3f2/Debug --target csvreader -- -j 2
    [ 50%] Linking CXX executable csvreader
    Undefined symbols for architecture x86_64:
      "Poco::AtomicCounter::AtomicCounter(int)", referenced from:
          Poco::ReferenceCounter::ReferenceCounter() in dataConn.cpp.o
      "Poco::AtomicCounter::~AtomicCounter()", referenced from:
          Poco::ReferenceCounter::~ReferenceCounter() in dataConn.cpp.o
      ... [many more]

这使用以下CMake构建文件:

    cmake_minimum_required(VERSION 3.3)
    project(csvreader)

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    set(SOURCE_FILES dataConn.cpp )
    #set(Boost_USE_STATIC_LIBS ON)
    #set(Boost_DEBUG ON)

    set(POCO_ROOT "/Users/alan/ClionProjects/csvreader/poco-1.6.1-all")
    set(POCO_INCLUDE_DIR "${POCO_ROOT}/Foundation/include" "${POCO_ROOT}/Util/include" "${POCO_ROOT}/Data/include" "${POCO_ROOT}/Data/SQLite/include")
    set(POCO_LIBRARY_DIR ${POCO_ROOT}/lib/Darwin/x86_64)
    message(STATUS "[ ${POCO_ROOT} ]" " POCO_ROOT")

    include_directories("${POCO_INCLUDE_DIR}")
    set(POCO_LIBS "")
    set(POCO_LIB_NAMES PocoFoundationd PocoUtild libPocoDatad PocoDataSQLited )
    message(STATUS "[ ${POCO_LIB_NAMES} ]" " POCO_LIB_NAMES")
    #FIND_LIBRARY(POCO_LIBS
    #        NAMES ${POCO_LIB_NAMES}
    #        PATHS ${POCO_LIBRARY_DIR}
    #        NO_DEFAULT_PATH)
    #message(STATUS "[ ${POCO_LIBS} ]" " POCO_LIBS")
    LINK_DIRECTORIES(${POCO_LIBRARY_DIR})
    add_executable(csvreader ${SOURCE_FILES} )
    target_link_libraries(csvreader  ${POCO_LIBRARY_DIR} ${POCO_LIBS})

我检查了试图访问的静态库,并且未找到第一个符号,在库中。所以这似乎是CMake无法自己找到库的问题。 如果它是相关的,这是在OS X 10.10.5上,并且所有内容都是64位构建的。

有人可以建议解决方案吗?

为了回应下面Robin的评论,我尝试取消注释FIND_LIBRARY并插入第一个库(其中包含符号Poco :: AtomicCounter :: AtomicCounter(int))。见下文。尝试使用此构建会导致相同的错误,上面的符号和其他符号都没有找到。


    cmake_minimum_required(VERSION 3.3)
    project(csvreader)

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    set(SOURCE_FILES dataConn.cpp )
    #set(Boost_USE_STATIC_LIBS ON)
    #set(Boost_DEBUG ON)

    set(POCO_ROOT "/Users/alan/ClionProjects/csvreader/poco-1.6.1-all")
    set(POCO_INCLUDE_DIR "${POCO_ROOT}/Foundation/include" "${POCO_ROOT}/Util/include" "${POCO_ROOT}/Data/include" "${POCO_ROOT}/Data/SQLite/include")
    set(POCO_LIBRARY_DIR ${POCO_ROOT}/lib/Darwin/x86_64)
    message(STATUS "[ ${POCO_ROOT} ]" " POCO_ROOT")

    include_directories("${POCO_INCLUDE_DIR}")
    set(POCO_LIBS "")
    set(POCO_LIB_NAMES PocoFoundationd PocoUtild libPocoDatad PocoDataSQLited )
    set(POCO_LIB_1 PocoFoundationd)
    message(STATUS "[ ${POCO_LIB_NAMES} ]" " POCO_LIB_NAMES")
    FIND_LIBRARY(POCO_LIBS
            NAMES ${POCO_LIB_1}
            PATHS ${POCO_LIBRARY_DIR}
            NO_DEFAULT_PATH)
    message(STATUS "[ ${POCO_LIBS} ]" " POCO_LIBS")
    #LINK_DIRECTORIES(${POCO_LIBRARY_DIR})
    add_executable(csvreader ${SOURCE_FILES} )
    target_link_libraries(csvreader  ${POCO_LIBRARY_DIR} ${POCO_LIBS})

0 个答案:

没有答案