[尝试编译boost和openssl时发生编译错误(使用Websocket ++或CPPRestSDK时)

问题描述 投票:0回答:1

我目前正在尝试使正在运行的tls websocket客户端在C ++中运行(这很麻烦,并且我已经尝试了CPP Rest SDK和Websocket ++。两者都吐出了一堆编译错误(见下文)。当我尝试使用不带tls的Websocket ++对其进行编译时,它会进行编译,因此该错误显然与SSL有关。

我尝试了不同的OpenSSL版本(1.0.1、1.0.2、1.1.0),不同的C ++版本(11、14甚至17),但是我无法编译它。

我用谷歌搜索,但没有一种解决方案有效。我在Ubuntu 16上,正在使用的生成命令如下所示:

g++ source/* -o test.out -Iinclude/ -std=c++14 -L/lib64 -lcurl -lboost_system -lssl -lcrypto -l pthread

以下是一些错误:

/usr/include/boost/asio/ssl/detail/impl/openssl_init.ipp: In constructor ‘boost::asio::ssl::detail::openssl_init_base::do_init::do_init()’:
/usr/include/boost/asio/ssl/detail/impl/openssl_init.ipp:43:23: error: expected id-expression before ‘(’ token
 mutexes_.resize(::CRYPTO_num_locks());

/usr/include/boost/asio/ssl/detail/impl/engine.ipp:221:9: error: ‘SSL_R_SHORT_READ’ was not declared in this scope
     ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ),

这是基本的源代码:

#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>
#include <iostream>

// pull out the type of messages sent by our config
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;

typedef websocketpp::client<websocketpp::config::asio_tls_client> client;

using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

void on_close(client* c, websocketpp::connection_hdl hdl) {
    c->get_alog().write(websocketpp::log::alevel::app, "Connection Closed");
}

int main(int argc, char* argv[]) {
    client c;

    std::string uri = "wss://gateway.discord.gg/";

    if (argc == 2) {
        uri = argv[1];
    }

    try {
        // set logging policy if needed
        c.clear_access_channels(websocketpp::log::alevel::frame_header);
        c.clear_access_channels(websocketpp::log::alevel::frame_payload);
        //c.set_error_channels(websocketpp::log::elevel::none);

        // Initialize ASIO
        c.init_asio();

        // Register our handlers
        c.set_open_handler(bind(&on_open,&c,::_1));
        c.set_fail_handler(bind(&on_fail,&c,::_1));
        c.set_message_handler(bind(&on_message,&c,::_1,::_2));
        c.set_close_handler(bind(&on_close,&c,::_1));

        // Create a connection to the given URI and queue it for connection once
        // the event loop starts
        websocketpp::lib::error_code ec;
        client::connection_ptr con = c.get_connection(uri, ec);
        c.connect(con);

        // Start the ASIO io_service run loop
        c.run();
    } catch (const std::exception & e) {
        std::cout << e.what() << std::endl;
    } catch (websocketpp::lib::error_code e) {
        std::cout << e.message() << std::endl;
    } catch (...) {
        std::cout << "other exception" << std::endl;
    }
}
c++ boost g++ cpprest-sdk
1个回答
0
投票

这已经很久了,但是如果有帮助,在g ++ cmd参数中添加-lcrypto -lssl可以解决我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.