2017-09-07 3 views
-2

Je tente d'utiliser le SDK CPPREST dans CLion sur un Mac en utilisant CMake. Je suis presque là, mais je ne peux pas sembler résoudre l'erreur de liaison suivant:CPPREST SDK sur CLion en utilisant CMake sur Mac

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 

J'ai indiqué -lssl et -lcrypto, mais toujours obtenir cette erreur « d'état de fil ». Basé sur des recherches, on dirait que ça vient d'OpenSSL. J'ai utilisé Homebrew pour installer CPPREST.

J'ai testé avec littéralement juste un bâtiment principal et la base comprend:

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

avec CMake de:

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}) 
+0

double possible de [Qu'est-ce qu'une erreur de symbole de référence externe non défini/non résolu et comment puis-je résoudre ce problème?] (Https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference -unresolved-external-symbol-error-et-how-do-i-fix) – user0042

+0

J'ai vérifié pour cela. J'ai littéralement juste un principal et inclut: #include #include

Répondre

0

Après avoir pris un certain temps, le problème de liaison est due à la CMake trouver les commandes ne fonctionnent pas correctement. J'ai pointé manuellement directement vers les bibliothèques pour OpenSSL et RESTCPP et le problème a été résolu.

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})