Skip to content

Fix build failure on modern macOS/Clang (Missing <experimental/coroutine>)#10

Open
marcinczeczko wants to merge 1 commit intomahilab:masterfrom
marcinczeczko:fix-for-macos-cxx20
Open

Fix build failure on modern macOS/Clang (Missing <experimental/coroutine>)#10
marcinczeczko wants to merge 1 commit intomahilab:masterfrom
marcinczeczko:fix-for-macos-cxx20

Conversation

@marcinczeczko
Copy link

This PR addresses a fatal compilation error encountered on modern macOS environments (specifically using Xcode 15+ and modern Clang) where the C++ Technical Specification (TS) header <experimental/coroutine> has been removed in favor of the standardized C++20 header.

The error during compilation

.../mahi-util/include/Mahi/Util/Coroutine.hpp:24:6: error: "No coroutine header found. Ensure you are using a C++20 compiler."
    #error "No coroutine header found. Ensure you are using a C++20 compiler."
     ^
.../mahi-util/include/Mahi/Util/Coroutine.hpp:41:28: error: no member named 'experimental' in namespace 'std'
using SuspendAlways = std::experimental::suspend_always;
                      ~~~~~^

Changes:

Added a preprocessor check using __has_include to detect the presence of the standard header.

Implemented a conditional namespace alias to map std::coroutine_handle, std::suspend_always, and std::suspend_never into the std::experimental namespace.

This allows the existing codebase to remain unchanged while supporting modern C++20 compilers that have moved out of the "experimental" phase.

Maintains backward compatibility for older systems/Linux environments that still rely on the <experimental/coroutine> path.

Testing:

Verified on macOS (Sequoia/Sonoma) with CMake 4.x and Clang (Apple LLVM 15/16).
Confirmed that the fix resolves the 'experimental/coroutine' file not found error.
Notes: Requires the project to be compiled with the C++20 standard (e.g., -DCMAKE_CXX_STANDARD=20).

Steps done:

$> mkdir build && cd build
$> cmake .. -DCMAKE_CXX_STANDARD=20 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
$> make

successfully compiled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant