android / ndk

The Android Native Development Kit
1.92k stars 253 forks source link

[BUG] Compilation Error with std::execution in C++17 #2038

Open bitforth opened 5 days ago

bitforth commented 5 days ago

Description

I'm trying to compile a C++ program using the Android NDK that relies on the C++17 feature std::execution.

During the build process, I encounter the following errors:

error: no member named 'par' in namespace 'std::execution'
error: no member named 'par_unseq' in namespace 'std::execution'

Sample Program:

#include <execution>
#include <algorithm>
#include <vector>

int main() {
    std::vector<int> vec = {1, 2, 3, 4, 5};
    std::for_each(std::execution::par, vec.begin(), vec.end(), [](int &n) { n *= 2; });
    return 0;
}

Compilation Command:

/Users/A.Chavez/Library/Android/sdk/ndk/27.0.11902837/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ \
  --target=aarch64-none-linux-android24 \
  --sysroot=/Users/A.Chavez/Library/Android/sdk/ndk/27.0.11902837/toolchains/llvm/prebuilt/darwin-x86_64/sysroot \
  -std=c++20 \
  -stdlib=libc++ \
  -I/Users/A.Chavez/Library/Android/sdk/ndk/27.0.11902837/sources/cxx-stl/llvm-libc++/include \
  -I/Users/A.Chavez/Library/Android/sdk/ndk/27.0.11902837/sources/cxx-stl/llvm-libc++abi/include \
  -I/Users/A.Chavez/Library/Android/sdk/ndk/27.0.11902837/sources/android/support/include \
  -c test.cpp

Context: I've set the APP_CPPFLAGS to -std=c++20 and APP_STL to c++_shared in my CMakeList.txt file. I am using NDK version 27.0.11902837 but this happens with any NDK that should support C++17 (NDK 26 too)

The documentation indicates that libc++ should support modern C++ features, but it seems std::execution might not be supported.

How can I resolve this error and successfully compile my program using the Android NDK?

Is there any specific configuration or additional steps required to enable support for std::execution?

I'm using CMake for building the project

Affected versions

r26, r27

Canary version

No response

Host OS

Mac

Host OS version

macOS 14.5

Affected ABIs

arm64-v8a

Build system

CMake

Other build system

No response

minSdkVersion

24

Device API level

24

appujee commented 5 days ago

Even llvm trunk doesn't have support for it: https://godbolt.org/z/8j9EPbdzY

bitforth commented 5 days ago

Even llvm trunk doesn't have support for it: https://godbolt.org/z/8j9EPbdzY

So does that mean that I'm going to have to rewrite the parts of my code that uses std::execution right?