我正在尝试构建我的项目,该项目使用带有 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] 删除。
我来说两句