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

时间:2017-10-02 08:32:19

标签: c++ boost g++ cpprest-sdk

我目前正在尝试使用C ++运行一个工作的websocket客户端(这是一个痛苦的罢工),我尝试过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;
    }
}

1 个答案:

答案 0 :(得分:1)

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

相关问题