Search code examples
c++cmakeboost-asio

Issues compiling with Asio 1.30.2 on macOS using Clang 15.0.0


I'm developing a C++ project on mac(Sonoma 14.6.1 (23G93)), and I'm trying to use Asio(https://think-async.com/Asio/) version 1.30.2. My development environment details are as follows:

  • Compiler: Apple clang version 15.0.0 (clang-1500.3.9.4)
  • Target: x86_64-apple-darwin23.6.0
  • posix
  • CMake version: 3.28

Here’s the relevant part of my CMakeLists.txt:

cmake_minimum_required(VERSION 3.28)
project(CPP_Framework)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(${CMAKE_SOURCE_DIR}/module/actor-framework-1.0.1)

include_directories(${CMAKE_SOURCE_DIR}/module/asio-1.30.2/include)
#include_directories(${CMAKE_SOURCE_DIR}/module/boost_1_85_0)
#include_directories(${CMAKE_SOURCE_DIR}/module/actor-framework-1.0.1/libcaf_core)
include_directories(${CMAKE_SOURCE_DIR}/source)

file(GLOB_RECURSE SOURCES "${CMAKE_SOURCE_DIR}/source/*.cpp")

# CMakeLists.txt
set(PROJECT_ROOT "${CMAKE_SOURCE_DIR}")

# Add this to your compile definitions
add_compile_definitions(PROJECT_ROOT="${PROJECT_ROOT}")

add_executable(CPP_Framework main.cpp ${SOURCES})

I have tried setting CMAKE_CXX_STANDARD to 11, 17, 20, and 23, and also toggled CMAKE_CXX_EXTENSIONS between ON and OFF. However, I keep encountering the following errors during build:

In file included from asio-1.30.2/include/asio.hpp:58:
In file included from asio-1.30.2/include/asio/buffered_stream.hpp:22:
In file included from asio-1.30.2/include/asio/buffered_write_stream.hpp:28:
In file included from asio-1.30.2/include/asio/write.hpp:1412:
asio-1.30.2/include/asio/impl/write.hpp:400:40: error: no type named 'executor_type' in 'std::shared_ptr<asio::basic_stream_socket<asio::ip::tcp>>'
    typedef typename AsyncWriteStream::executor_type executor_type;

In file included from asio-1.30.2/include/asio.hpp:30:
In file included from asio-1.30.2/include/asio/basic_datagram_socket.hpp:20:
In file included from asio-1.30.2/include/asio/basic_socket.hpp:23:
asio-1.30.2/include/asio/detail/io_object_impl.hpp:58:25: error: no member named 'get_executor' in 'asio::execution_context'
      executor_(context.get_executor())


asio-1.30.2/include/asio/impl/write.hpp:338:21: error: no member named 'async_write_some' in 'std::shared_ptr<asio::basic_stream_socket<asio::ip::tcp>>'
            stream_.async_write_some(buffers_.prepare(max_size),

I have also included the Boost headers and libraries, but the errors persist.

Has anyone encountered similar issues when compiling with Asio 1.30.2? Any help on how to resolve these errors would be greatly appreciated. Thanks!


Solution

  • error: no type named 'executor_type' in 'std::shared_ptr<asio::basic_stream_socket<asio::ip::tcp>>' typedef typename AsyncWriteStream::executor_type executor_type;

    That error indicates that you are passing a shared pointer where an AsyncWriteStream is required. Most like you have to add *, so instead of

     asio::async_write(psocket, ...)
    

    It should read

     asio::async_write(*psocket, ...)