使用休息床的链接器错误

Linker error using restbed

所以,我正在尝试编译我的程序,该程序将 restbed 作为依赖项。 我已经使用以下命令编译了 restbed:

cmake -DBUILD_TESTS=NO -DBUILD_SSL=YES -DBUILD_SHARED=NO
make -j4 install

编译 restbed 不会导致任何错误。

现在的问题:

我正在使用此处的示例源代码:https://github.com/Corvusoft/restbed

这是我的 CMakeLists:

cmake_minimum_required (VERSION 2.6)
project(FDRService CXX)

# Setup
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(CMAKE_BINARY_DIR "./build")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

# FD Variables
set(FDRService_VERSION_MAJOR 1)
set(FDRService_VERSION_MINOR 0)

set(FDRService_INCLUDE_DIR "./include")
set(FDRService_SOURCE_DIR "./src")

# RestBED
set(RESTBED_ROOT "dependency/restbed/distribution")
set(RESTBED_INCLUDE_DIR "${RESTBED_ROOT}/include")
set(RESTBED_LIBRARY_DIR "${RESTBED_ROOT}/library")

# find all libraries
file(GLOB_RECURSE RESTBED_LIBRARY_FILES
    "${RESTBED_LIBRARY_DIR}/*.a"
)

include_directories(${RESTBED_INCLUDE_DIR})

# find project source files
file(GLOB_RECURSE FDRService_FILES
    "${FDRService_INCLUDE_DIR}/*.h"
    "${FDRService_INCLUDE_DIR}/*.hpp"
    "${FDRService_SOURCE_DIR}/*.c"
    "${FDRService_SOURCE_DIR}/*.cpp"
)

add_executable(FDRService ${FDRService_FILES})
target_link_libraries(FDRService ${RESTBED_LIBRARY_FILES})

当我尝试编译我的项目时,出现以下链接器错误:

http://pastebin.com/hXPmAV2W(Whosebug 的文本太多...)

我的猜测是 OpenSSL 库没有链接到 restbed 的静态 .a 文件中,但我在构建命令中输入了 -DBUILD_SSL。

我希望你们中的任何人都可以帮助我解决这个问题。这让我发疯。

如果您需要更多信息,请告诉我,我会编辑这个 post。

我们使用以下 cmake 模块来定位依赖于 Restbed 的项目所需的依赖项。

Findrestbed.cmake

find_path( restbed_SOURCE CMakeLists.txt HINTS "${CMAKE_SOURCE_DIR}/dependency/restbed" )

if ( restbed_SOURCE )
    set( restbed_FOUND TRUE )
    set( restbed_BUILD "${CMAKE_CURRENT_BINARY_DIR}/restbed_build" )
    set( restbed_DISTRIBUTION "${CMAKE_CURRENT_BINARY_DIR}/distribution" )

    include( ExternalProject )
    ExternalProject_Add( restbed SOURCE_DIR ${restbed_SOURCE}
                         PREFIX restbed_build
                         INSTALL_DIR ${restbed_DISTRIBUTION}
                         CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${restbed_DISTRIBUTION} -DBUILD_SSL=${BUILD_SSL} -DBUILD_SHARED=NO )

    set( restbed_INCLUDE "${restbed_DISTRIBUTION}/include" )
    set( restbed_LIBRARY "${restbed_DISTRIBUTION}/library/${CMAKE_STATIC_LIBRARY_PREFIX}restbed${CMAKE_STATIC_LIBRARY_SUFFIX}" )

    message( STATUS "${Green}Found Restbed include at: ${restbed_SOURCE}${Reset}" )
else ( )
    message( FATAL_ERROR "${Red}Failed to locate Restbed dependency.${Reset}" )
endif ( )

Findopenssl.cmake

find_library( ssl_LIBRARY ssl ssleay32 HINTS "${CMAKE_SOURCE_DIR}/dependency/restbed/dependency/openssl/out32dll" "${CMAKE_SOURCE_DIR}/dependency/restbed/dependency/openssl" "/usr/lib" "/usr/local/lib" "/opt/local/lib" )
find_library( crypto_LIBRARY crypto libeay32 HINTS "${CMAKE_SOURCE_DIR}/dependency/restbed/dependency/openssl/out32dll" "${CMAKE_SOURCE_DIR}/dependency/restbed/dependency/openssl" "/usr/lib" "/usr/local/lib" "/opt/local/lib" )
find_path( ssl_INCLUDE openssl/ssl.h HINTS "${CMAKE_SOURCE_DIR}/dependency/restbed/dependency/openssl/inc32" "${CMAKE_SOURCE_DIR}/dependency/restbed/dependency/openssl/include" "/usr/include" "/usr/local/include" "/opt/local/include" )

if ( ssl_INCLUDE AND ssl_LIBRARY AND crypto_LIBRARY )
    set( OPENSSL_FOUND TRUE )
    add_definitions( -DBUILD_SSL=TRUE )

    if ( APPLE AND BUILD_SSL )
        set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" )
    endif( )

    message( STATUS "${Green}Found OpenSSL library at: ${ssl_LIBRARY}${Reset}" )
    message( STATUS "${Green}Found OpenSSL include at: ${ssl_INCLUDE}${Reset}" )
    message( STATUS "${Green}Found Crypto library at: ${crypto_LIBRARY}${Reset}" )
else ( )
    message( FATAL_ERROR "${Red}Failed to locate OpenSSL dependency. see dependency/restbed/dependency/openssl; ./config shared; make all${Reset}" )
endif ( )

您可以在 RestQ GIT repository.

中查看实际操作示例