包含 boost/beast/http.hpp 时出现多个错误

Mil4eg

我正在尝试构建我的项目,该项目使用带有 cmake 的 boost beast 库。当我只使用 boost asio 库时,一切正常。但是当我添加 boost/beast/http.hpp 标头时,cmake 会出现大量错误。

CMake文件:


cmake_minimum_required(VERSION 3.10)

project(ConsoleChat.Server)

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost 1.75.0 REQUIRED COMPONENTS system filesystem)

add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)

include_directories(${Boost_INCLUDE_DIRS})

link_directories(${Boost_LIBRARY_DIRS})

add_executable(ConsoleChat.Server main.cpp)
target_link_libraries(ConsoleChat.Server ${Boost_LIBRARIES})

代码文件:

#include <cstdlib>
#include <memory>
#include <thread>
#include <iostream>
#include <string>

#include <boost/asio.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/beast/version.hpp>
#include <boost/beast/http.hpp>

namespace net = boost::asio;
namespace beast = boost::beast;
namespace http = beast::http;
using tcp = boost::asio::ip::tcp;

int main(int argc, char* argv[])
{
    try
    {
        if (argc != 3)
        {
            std::cout <<
                "Usage: websocket-chat-multi <address> <port>\n" <<
                "Example:\n" <<
                "    websocket-chat-server 0.0.0.0 8080\n";
            return EXIT_FAILURE;
        }

        auto const address = net::ip::address::from_string(argv[1]);//net::ip::make_address(argv[1]); 
        auto const port = static_cast<unsigned short>(std::atoi(argv[2]));

        net::io_service ios{1};

        tcp::acceptor acceptor{ios, {address, port}};
    
        for (;;)
        {
            tcp::socket socket{ios};

            acceptor.accept(socket);
        }
    }
    catch(const std::exception& e)
    {
        std::cout << e.what() << '\n';
    }
}

错误示例:

In file included from /usr/local/include/boost/beast/core/buffer_traits.hpp:14,
                 from /usr/local/include/boost/beast/http/basic_dynamic_body.hpp:14,
                 from /usr/local/include/boost/beast/http.hpp:15,
                 from /home/kudryavii/projects/ConsoleChat/ConsoleChat.Server/main.cpp:10:
/usr/local/include/boost/beast/core/detail/buffer_traits.hpp:66:18: error: ‘is_const_buffer_sequence’ is not a member of ‘boost::beast::net’
   66 |             net::is_const_buffer_sequence<B>::value>::type>
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/beast/core/detail/buffer_traits.hpp:66:18: error: ‘is_const_buffer_sequence’ is not a member of ‘boost::beast::net’

我尝试添加所有 boost 库来查找包部分,但这没有帮助。

是的。预处理后的源确认的第一提及is_const_buffer_sequence是从线116485(EEK),这归因于

# 49 "/usr/local/include/boost/beast/core/detail/buffer_traits.hpp" 3

从第 116467 行开始。在我的系统上,这不是第一次提及,因为(显然?)声明在boost_1_75_0/boost/asio/buffer.hpp之前:

# 2422 "/home/sehe/custom/boost_1_75_0/boost/asio/buffer.hpp" 2 3 4

它的包含树检查为¹

/usr/include/boost/asio.hpp -->
  /usr/include/boost/asio/basic_datagram_socket.hpp -->
    /usr/include/boost/asio/datagram_socket_service.hpp -->
      /usr/include/boost/asio/detail/null_socket_service.hpp -->
        /usr/include/boost/asio/buffer.hpp

所以,让我们看看我们是否可以为您的预处理源跟踪类似的路径。

减少所有行指令(通过剥离实际行号并消除后续重复项)我看到了预期的轨迹。但是,然后我发现了差异:

# 124 "/usr/local/include/boost/asio/buffer.hpp" 3
private:
  friend void* boost::asio::detail::buffer_cast_helper(
      const mutable_buffer& b);
  friend std::size_t boost::asio::detail::buffer_size_helper(
      const mutable_buffer& b);

  void* data_;
  std::size_t size_;

嗯?在 1.75.0 这些朋友不存在:https : //github.com/boostorg/asio/blob/boost-1.75.0/include/boost/asio/buffer.hpp

您显然在那里安装了 Boost 1.75.0 以外的其他东西 - 这很有趣,因为 CMake 的 FindPackage 应该抱怨?无论如何,再深入一些:

git grep -l is_const_buffer_sequence boost-1.{60..75}.0 | grep buffer.hpp
boost-1.66.0:include/boost/asio/buffer.hpp
boost-1.67.0:include/boost/asio/buffer.hpp
boost-1.68.0:include/boost/asio/buffer.hpp
boost-1.69.0:include/boost/asio/buffer.hpp
boost-1.70.0:include/boost/asio/buffer.hpp
boost-1.71.0:include/boost/asio/buffer.hpp
boost-1.72.0:include/boost/asio/buffer.hpp
boost-1.73.0:include/boost/asio/buffer.hpp
boost-1.74.0:include/boost/asio/buffer.hpp
boost-1.75.0:include/boost/asio/buffer.hpp

也许还可以找出朋友何时被删除:

git grep -l friend boost-1.{60..75}.0 | grep buffer.hpp
boost-1.60.0:include/boost/asio/buffer.hpp
boost-1.61.0:include/boost/asio/buffer.hpp
boost-1.62.0:include/boost/asio/buffer.hpp
boost-1.63.0:include/boost/asio/buffer.hpp
boost-1.64.0:include/boost/asio/buffer.hpp
boost-1.65.0:include/boost/asio/buffer.hpp

就在同一时刻。看起来我们可以确定您的 boost asio 标头的上限:

git log -Sfriend include/boost/asio/buffer.hpp
commit b60e92b13ef68dfbb9af180d76eae41d22e19356
Author: Christopher Kohlhoff <[email protected]>
Date:   Mon Oct 23 14:27:36 2017 +1100

    Initial merge of Networking TS compatibility.
    
    Merged from chriskohlhoff/asio master branch as of commit
    4a4d28b0d24c53236e229bd1b5f378c9964b1ebb.

这与引入is_const_buffer_sequence. Git 确认你的 Asio 版本肯定是 boost 1.65.0 或更旧的²:

git tag --contains b60e92b13ef68dfbb9af180d76eae41d22e19356
boost-1.66.0
boost-1.67.0
boost-1.68.0
boost-1.69.0
boost-1.69.0-beta1
boost-1.70.0
boost-1.70.0.beta1
boost-1.71.0
boost-1.71.0.beta1
boost-1.72.0
boost-1.72.0.beta1
boost-1.73.0
boost-1.73.0.beta1
boost-1.74.0
boost-1.74.0.beta1
boost-1.75.0
boost-1.75.0.beta1

现在疯狂的是:Boost Beast 直到 Boost 1.66.0 才存在

简而言之,您的安装已损坏。首先,您有一个带有新 Beast 标头的旧 Asio。其次,它的安装方式使得 CMake 显然将其检测为满足 1.75.0 要求的有效 Boost 安装。


¹(这不是 100% 完全保真,因为我使用 vim 的:check!命令进行了检查,该命令不使用 libclang 或任何选项/预处理器感知)

² 当然,您只需查看/usr/include/boost/version.hpp或打印以下值会容易得多BOOST_LIB_VERSION

std::cout << BOOST_LIB_VERSION << "\n";

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

C ++ Boost-iostream:包含filtering_streambuf.hpp时出现神秘错误

SWIG中包含OpenCV core.hpp时的语法错误

包含boost / optional.hpp时C2143语法错误

在 MacOS/CRAN 上构建 R 包时包含 boost tokenizer.hpp 文件时出错

BGL:包含random_spanning_tree.hpp时,对strong_components的调用无法编译

包含Embarcadero C ++ Builder中生成的VCL样式实用程序的.hpp文件时出错

在R包中包含hpp文件

使用 main() 包含来自其他 cpp(hpp) 文件的函数

如何在vlfw中包含Vulkan-hpp?

尝试使用extern在多个源文件中包含变量时出现错误

具有全局功能的hpp / cpp拆分:...错误的多个定义

如何在CMakeLists.txt中包含h / hpp头文件,而不是cpp或其他hpp文件

使用 dllimport/dllexport 宏在多个项目中包含标头时出现 VC++ 链接器错误

执行make -j4时出现log4cxx / logger.h或libcql / cql.hpp致命错误

包含glad.h时出现分段错误

当我包含使用“distinct”时出现语法错误

变量名称包含空格时出现ncks错误

在 Ruby 中包含模块的克隆时出现类型错误

为什么在尝试保存包含枚举的实体时出现错误?

每次包含变量 ntaReqRef 时都会出现 ajax 错误

在项目中包含 X 射线刮刀时出现 Npm 错误

包含 <iostream> 时出现“未定义引用”错误

使用pyAudioAnalysis时出现“行包含NULL字节”错误

我是否必须安装“libbitcoin-server”才能包含“bitcoin.hpp”?

我无法在项目中包含升压头文件mapd_file.hpp

如何处理静态库中任何.cpp中未包含的.hpp

为什么包含“ boost / multiprecision / cpp_int.hpp”会破坏套接字?

包含python.h和boost / python.hpp的C ++导致SEH异常

在 VSCode“SFML/Graphics.hpp 没有这样的文件或目录”gcc 中包含 SFML 库