boostorg / asio

Boost.org asio module
http://boost.org/libs/asio
1.25k stars 418 forks source link

Macro BOOST_ASIO_HAS_FILE not defined #409

Open JRazek opened 1 year ago

JRazek commented 1 year ago

I am trying to compile basic program:


#include <boost/asio/basic_stream_file.hpp>
#include <iostream>

auto main() -> int { auto b = boost::asio::basic_stream_file{}; }

g++ ./not_compiling.cpp -std=c++20 -lboost -o boost_testing I receive following compilation error

$ g++ ./not_compiling.cpp -std=c++20 -lboost -o boost_testing
./not_compiling.cpp: In function ‘int main()’:
./not_compiling.cpp:5:38: error: ‘boost::asio’ has not been declared
    5 | auto main() -> int { auto b = boost::asio::basic_stream_file{}; }

I believe that it is an issue with undefined macro BOOST_ASIO_HAS_FILE.

I've tried installing boost from arch repo, compiling from source on boost-1.81.0/1.80.0 branches with the same result.

extra/boost 1.81.0-3 [installed]
    Free peer-reviewed portable C++ source libraries (development headers)
g++ --version
g++ (GCC) 12.2.1 20230201

Manually defining macro in /usr/include/boost/asio/detail/config.hpp did not help and generated another compilation errors.

Now, why is that macro not defined? How can I fix it?

Techmeology commented 1 year ago

I ran into the same issue (also on Arch). I was able to work around it by defining BOOST_ASIO_HAS_IO_URING and linking against liburing.

Techmeology commented 1 year ago

It turns out you should also give BOOST_ASIO_DISABLE_EPOLL, otherwise you can get epoll re-registration: File exists [system:17] under certain circumstances when forking.

From the revision history:

The backend is disabled by default, and must be enabled by defining both ASIO_HAS_IO_URING and ASIO_DISABLE_EPOLL.

Simply defining ASIO_HAS_IO_URING alone will enable the backend without using it for the existing I/O objects. This allows it to be used for I/O objects that require io_uring support, such as files.