Clion显示错误,但可以使用Cmake成功构建代码
Clion show errors but the codes can be built successfully with Cmake
我正在尝试使用 IDE CLion 了解 Boost::Beast。
这是我的环境:
- MacBook Pro(15英寸2018(与酷睿i9
- 编译器: 苹果叮当版本 11.0.3 (clang-1103.0.32.62( 目标:x86_64苹果达尔文19.5.0 螺纹型号:磅 已安装目录:/Library/Developer/CommandLineTools/usr/bin
- Clion 版本:CLion 2020.1.2 内部版本 #CL-201.7846.88,构建于 2020 年 6 月 3 日
- 提升: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() {}
还有CMkaeLists.txt
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)
构建的所有内容都正常,但 IDE 显示语句co_await http::async_write(stream, req, use_awaitable);
的错误:
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...
你需要告诉CLion你的工具链。具体来说,CLion 应该使用 CMake 编译数据库。我想这通常应该"自动"发生,但显然它不同步。
您也可以选择"不同"的完成引擎
- 设置/首选项 |编辑 |一般 |代码完成
具体来说,最近的CLion版本旨在解决一致性问题,例如您所希望的问题:https://blog.jetbrains.com/clion/2020/04/clion-2020-1-cuda-clang-embedded/
在 2020.1 迭代中,我们完善了 Clang 提供的补全功能(通过修复数十个相关问题并添加缺失的补全功能(,最终启用了 Clang 是 CLion 中代码完成的唯一提供程序的模式作为默认值。这解决了一些优先级和排序问题。
经过大量的尝试,我产生了一些想法:
Clion 2020.1 使用特定的 clangd(v10.0( 来完成代码,但最新的 clangd 与 Boost::Asio/Boost::Beast 1.72 不完全兼容某些 C++20 语法,例如协程支持。我不知道起源是什么,也许是 Boost::Beast/Asio 兼容性问题,或者只是最新 clangd 的错误。
我在Visual Studio Code中尝试了clangd 10和clangd 9的想法,因为Clion不支持替代clangd。叮当声 10 显示上面的错误,但叮当声 9 没有。
因此,在这种情况下,似乎在 Clion 支持替代 clangd 或 Boost 找出兼容性问题之前,问题无法解决。
https://youtrack.jetbrains.com/issue/CPP-18725#focus=streamItem-27-3903547.0-0
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用CMake创建QML插件
- cmake如何在fedora工作站中找到boost静态库包
- 使用CMake检测支持的C++标准
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- cmake在我的项目中所需的所有静态库都不成功
- 尽管测试成功,CppUnit测试核心仍被丢弃.为什么
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 无法链接 CMake 中的本地库
- CMake WxWidgets项目成功地在Linux上构建,但没有在Windows上构建
- Clion显示错误,但可以使用Cmake成功构建代码
- 成功的生成文件失败,在 CLion 中出现"identical" CMake
- 首先我已经成功安装了 caffe,但是当我运行一个 caffe 项目时,cmake 还可以,后来会发出很多错误
- 将cxxtest链接在cmake中,它说它成功了,但无法构建
- Cmake并需要两次运行才能成功构建代码
- 未安装的包上的 CMake "find_package"命令意外成功
- CMake FIND_PACKAGE成功,但返回错误的路径