简体   繁体   English

使用Mac上的CMake的CLion上的CPPREST SDK

[英]CPPREST SDK on CLion using CMake on Mac

I am attempting to use the CPPREST SDK in CLion on a Mac using CMake. 我试图在使用CMake的Mac上的CLion中使用CPPREST SDK。 I'm almost there, but I cannot seem to resolve the following linker error: 我快到了,但似乎无法解决以下链接器错误:

Undefined symbols for architecture x86_64:
  "_ERR_remove_thread_state", referenced from:
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in PongRemote.cpp.o

I have specified -lssl and -lcrypto, but still get this "thread state" error. 我指定了-lssl和-lcrypto,但仍然收到此“线程状态”错误。 Based on some research, it looks like it is coming from OpenSSL. 根据一些研究,它似乎来自OpenSSL。 I used Homebrew to install CPPREST. 我使用Homebrew安装CPPREST。

I have tested this with literally just a main and the basic includes: 我实际上已经对它进行了测试,而基本测试包括:

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

with a CMake of: 的CMake:

project(cpprest)
cmake_minimum_required(VERSION 3.8)
set(CMAKE_CXX_STANDARD 14)

# BOOST PACKAGE
find_package(Boost REQUIRED COMPONENTS
    atomic
    chrono
    date_time
    exception
    filesystem
    random
    regex
    serialization
    system
    thread
    )
include_directories(${Boost_INCLUDE_DIRS})
IF (!Boost_FOUND)
    MESSAGE("*** ERROR *** Boost package not found")
    RETURN()
ENDIF ()

# Microsoft RESTful API Package (Casablanca)
set(CPPREST_LIBRARIES "/usr/local/opt/openssl/lib")
include_directories("/usr/local/opt/openssl/include")

# Compile and link
# Build the core library and executable
include_directories(${CMAKE_SOURCE_DIR})
set(SOURCE_FILES
    main.cpp
    )
set(LINK_LIBRARIES
    ${Boost_LIBRARIES}
    ${CPPREST_LIBRARIES}
    -lssl
    -lcrypto
    )
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})

After taking some time, the linking problem was due to the CMake find commands not working properly. 花费一些时间后,链接问题是由于CMake find命令无法正常工作。 I manually pointed directly to the libraries for both OpenSSL and RESTCPP and the problem was fixed. 我手动直接指向OpenSSL和RESTCPP的库,此问题已解决。

Project(cpprest)
cmake_minimum_required(VERSION 3.8)
set(CMAKE_CXX_STANDARD 17)

# BOOST PACKAGE
set(Boost_USE_MULTITHREADED      ON) # Default ON
set(Boost_USE_STATIC_LIBS        ON) # Default OFF
set(Boost_USE_DEBUG_RUNTIME     OFF) # Default ON
set(Boost_USE_DEBUG_PYTHON      OFF) # Default OFF
set(Boost_USE_STLPORT           OFF) # Default OFF
find_package(Boost REQUIRED COMPONENTS
    atomic
    chrono
    date_time
    exception
    filesystem
    program_options
    random
    regex
    system
    serialization
    thread
    )
IF (!Boost_FOUND)
    MESSAGE("*** ERROR *** Boost package not found")
    RETURN()
ENDIF ()
include_directories(${Boost_INCLUDE_DIRS})
MESSAGE("Boost_INCLUDE_DIRS:\t" ${Boost_INCLUDE_DIRS})

# Open SSL Package
set(OpenSSL_INCLUDE /usr/local/opt/openssl/include)
set(OpenSSL_LIBRARIES
    /usr/local/opt/openssl/lib/libcrypto.dylib
    /usr/local/opt/openssl/lib/libssl.dylib)
include_directories(${OpenSSL_INCLUDE})

# Microsoft RESTful API Package (Casablanca)
set(CppREST_INCLUDE /usr/local/opt/cpprestsdk/include)
set(CppREST_LIBRARIES /usr/local/opt/cpprestsdk/lib/libcpprest.dylib)
include_directories(${CppREST_INCLUDE})

# Compile and link
# Build the core library and executable
set(SOURCE_FILES main.cpp)
set(LINK_LIBRARIES
    ${Boost_LIBRARIES}
    ${OpenSSL_LIBRARIES}
    ${CppREST_LIBRARIES}
    )
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM