简体   繁体   English

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

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

I am attempting to create a TCP server using boost.asio and following the examples you use co_spawn to start the listener function in a new thread. 我试图使用boost.asio创建一个TCP服务器,并按照示例使用co_spawn在新线程中启动侦听器功能。

When I try to use boost::asio::co_spawn Microsoft Visual Studios tells me it is undefined, I have included all files the boost example does. 当我尝试使用boost::asio::co_spawn Microsoft Visual Studios告诉我它是未定义的,我已经包含了boost示例所做的所有文件。

TcpServer.h 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 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()
{
}

The above code tells me that co_spawn is undefined, I have searched other name spaces and checked for alternative functions and there is none. 上面的代码告诉我co_spawn是未定义的,我已经搜索了其他名称空间并检查了替代功能,但没有。 I thought maybe it was outdated documentation but the boost.asio reference for version 1.70.1 still lists co_spawn as a free function. 我想也许这是过时的文件,但boost.asio进行版本参考1.70.1还列出co_spawn作为一个免费的功能。 See here 这里

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

boost.asio has preprocessor code to detect the capabilities of the compiler and only turn on coroutine support if the compiler supports it. boost.asio具有预处理器代码来检测编译器的功能,并且只有在编译器支持的情况下才启用协程支持。

For MSVC, I think you will need to add the compiler flag /await to the compiler command line option list. 对于MSVC,我认为您需要将编译器标志/await添加到编译器命令行选项列表中。

reference: https://docs.microsoft.com/en-us/cpp/build/reference/await-enable-coroutine-support?view=vs-2019 参考: 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