【发布时间】:2021-06-13 03:36:06
【问题描述】:
我正在尝试构建我的项目,该项目使用带有 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 库来查找包部分,但这没有帮助。
【问题讨论】:
-
@Tsyvarev 发布了第一条错误消息。
-
你能在某处提供预编译源吗?通常你应该能够通过
make main.i得到它(它会输出类似Preprocessing CXX source to CMakeFiles/sotest.dir/main.cpp.i的东西)。警告文件会很大(7.4M herem,但只有 600k xzipped),但您可以将其放在 pastebin 甚至 wetransfer 上。或者,您可以查看一下是否可以自己从那里发现问题 -
@sehe 我检查了 CmakeFiles/.dir 目录,但找不到 main.cpp.i。您是在谈论在 cmake --build 命令调用上显示的完整错误消息,因为它也很大?
-
我不是。你必须明确地告诉你的构建工具来实现这个目标,就像我说的那样,通常是
make main.i或ninja main.i等。 -
@sehe 知道了。此处上传文件:filebin.net/ebquhvt5flvz88pi。我试图自己理解文件,但什么都听不懂......
标签: c++ boost cmake boost-asio boost-beast