C++ Clion显示错误,但使用Cmake可以成功生成代码
我正在尝试通过IDE CLion了解Boost::Beast 这是我的环境:C++ Clion显示错误,但使用Cmake可以成功生成代码,c++,boost,cmake,boost-beast,C++,Boost,Cmake,Boost Beast,我正在尝试通过IDE CLion了解Boost::Beast 这是我的环境: MacBook Pro(15英寸,2018年)带核心i9 编译器: Apple clang 11.0.3版(clang-1103.0.32.62) 目标:x86_64-apple-darwin19.5.0 线程模型:posix InstalledDir:/Library/Developer/CommandLineTools/usr/bin Clion版本:Clion 2020.1.2构建#CL-201.7846.88
- MacBook Pro(15英寸,2018年)带核心i9
- 编译器: Apple clang 11.0.3版(clang-1103.0.32.62) 目标:x86_64-apple-darwin19.5.0 线程模型:posix InstalledDir:/Library/Developer/CommandLineTools/usr/bin
- Clion版本:Clion 2020.1.2构建#CL-201.7846.88,于2020年6月3日构建
- Boost:1.72由自制软件安装
#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <iostream>
namespace beast = boost::beast;
namespace http = beast::http;
namespace net = boost::asio;
using tcp = net::ip::tcp;
using boost::asio::awaitable;
using boost::asio::use_awaitable;
awaitable<void> test() {
net::io_context ctx;
tcp::resolver resolver(ctx);
http::response<http::dynamic_body> res;
auto const results =
co_await
resolver.async_resolve("www.google.com", "80", use_awaitable);
beast::tcp_stream stream(ctx);
// Set the timeout.
stream.expires_after(std::chrono::seconds(30));
// Make the connection on the IP address we get from a lookup
co_await
stream.async_connect(results, use_awaitable);
// Set up an HTTP GET request message
http::request<http::string_body> req{http::verb::get, "/", 5};
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
// Set the timeout.
stream.expires_after(std::chrono::seconds(30));
// Send the HTTP request to the remote host
co_await http::async_write(stream, req, use_awaitable);
}
int main() {}
构建的一切都正常,但是IDE为语句co_wait http::async_write(stream、req、use_waitable)显示错误代码>:
带有推断返回类型的函数“async\u write”在定义为“async\u write”之前不能使用您需要告诉CLion您的工具链。具体来说,CLion应该使用CMake。我想这通常应该是“自动”发生的,但显然是不同步的
您也可能选择“不同”的完成引擎
- 设置/首选项|编辑器|常规|代码完成
具体而言,最近的CLion版本旨在解决一致性问题,如您描述的问题:
在2020.1迭代期间,我们完善了Clang提供的完成(通过修复数十个相关问题并添加缺少的完成特性),并最终启用了Clang是CLion中唯一一个代码完成提供者的模式作为默认模式。这解决了一些优先级和排序问题
经过无数次尝试,我产生了一些想法:
Clion 2020.1使用特定的clangd(v10.0)完成代码,但对于某些C++20语法(如协同程序支持),最新的clangd与Boost::Asio/Boost::Beast 1.72不完全兼容。我不知道原因是什么,可能是Boost::Beast/Asio兼容性问题,或者只是最新版本的一个bug
我在我的VisualStudio代码中用Clangd10和Clangd9尝试了我的想法,因为Clion不支持替代clangd。clangd 10显示上述错误,但clangd 9不显示
因此,在这种情况下,在Clion支持alternative clangd或Boost解决兼容性问题之前,问题似乎无法解决
cmake_minimum_required(VERSION 3.16)
project(untitled)
if(APPLE)
include_directories(/usr/local/include)
endif()
find_package(Boost REQUIRED)
set(CMAKE_CXX_STANDARD 20)
add_executable(untitled main.cpp)
Function 'async_write<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::executor, boost::beast::unlimited_rate_policy>, true, boost::beast::http::basic_string_body<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost::beast::http::basic_fields<std::__1::allocator<char> >, const boost::asio::use_awaitable_t<boost::asio::executor> &>' with deduced return type cannot be used before it is defined 'async_write<boost::beast::basic_stream<boost::asio::ip::tcp, boost::asio::executor, boost::beast::unlimited_rate_policy>, true, boost::beast::http::basic_string_body<char, std::__1::char_traits<char>, std::__1::allocator<char> >, boost...