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



我正试图构建一个使用cmake的boost beast库的项目。当我只使用boost asio库时,一切都可以构建。但是当我添加boost/best/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 8080n";
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

它的include树检查为

/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

就在同一时刻。看起来我们可以确定你的助推asio标题的上限:

git log -Sfriend include/boost/asio/buffer.hpp
commit b60e92b13ef68dfbb9af180d76eae41d22e19356
Author: Christopher Kohlhoff <chris@kohlhoff.com>
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版本肯定是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才存在

简而言之,您的安装已损坏。首先,你有一个旧的阿西奥与新的野兽标题。其次,它的安装方式使得CMake显然检测到它是一个满足1.75.0要求的有效Boost安装。


(正如我使用vim的:check!命令检查的那样,这不是100%的全真度,该命令不使用libclang或任何选项/预处理器感知(

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

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

相关内容

最新更新