簡體   English   中英

在MSVC中未定義boost :: asio :: co_spawn

[英]boost::asio::co_spawn is undefined in MSVC

我試圖使用boost.asio創建一個TCP服務器,並按照示例使用co_spawn在新線程中啟動偵聽器功能。

當我嘗試使用boost::asio::co_spawn Microsoft Visual Studios告訴我它是未定義的,我已經包含了boost示例所做的所有文件。

TcpServer.h

#include <iostream>
#include <string>

#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/coroutine.hpp>

using namespace boost::asio;

class TcpServer
{
public:
    TcpServer(int port);
    ~TcpServer();
private:

};

TcpServer.cpp

#include "TcpServer.h"


/*
    Create a TcpServer on a given port
*/
TcpServer::TcpServer(int port)
{
    io_context ioCtx(1);

    /* E0020    identifier "co_spawn" is undefined  */
    co_spawn();
}


TcpServer::~TcpServer()
{
}

上面的代碼告訴我co_spawn是未定義的,我已經搜索了其他名稱空間並檢查了替代功能,但沒有。 我想也許這是過時的文件,但boost.asio進行版本參考1.70.1還列出co_spawn作為一個免費的功能。 這里

我正在使用Boost:1.70.1 Microsoft Visual Studio 2017:v15.9.7

boost.asio具有預處理器代碼來檢測編譯器的功能,並且只有在編譯器支持的情況下才啟用協程支持。

對於MSVC,我認為您需要將編譯器標志/await添加到編譯器命令行選項列表中。

參考: https : //docs.microsoft.com/zh-cn/cpp/build/reference/await-enable-coroutine-support?view=vs-2019

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM