std::experimental::optional with ndk/clang

1.6k views Asked by At

I am trying to build my project which uses std::experimental::optional. For Linux it compiled just fine, but for android/ndk the compiler throws:

error: no member named 'experimental' in namespace 'std'

I am building with the polly toolchain android-ndk-r17-api-24-armeabi-v7a-clang-libcxx14 and set(CMAKE_CXX_STANDARD 14)

# Copyright (c) 2015-2018, Ruslan Baratov
# Copyright (c) 2017-2018, Robert Nitsch
# Copyright (c) 2018, David Hirvonen
# All rights reserved.

if(DEFINED POLLY_ANDROID_NDK_R17_API_24_ARMEABI_V7A_CLANG_LIBCXX14_CMAKE_)
  return()
else()
  set(POLLY_ANDROID_NDK_R17_API_24_ARMEABI_V7A_CLANG_LIBCXX14_CMAKE_ 1)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_clear_environment_variables.cmake")

include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_init.cmake")

set(ANDROID_NDK_VERSION "r17")
set(CMAKE_SYSTEM_VERSION "24")
set(CMAKE_ANDROID_ARCH_ABI "armeabi-v7a")
set(CMAKE_ANDROID_ARM_NEON TRUE)
set(CMAKE_ANDROID_ARM_MODE TRUE) # 32-bit ARM
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang")
set(CMAKE_ANDROID_STL_TYPE "c++_static") # LLVM libc++ static

polly_init(
    "Android NDK ${ANDROID_NDK_VERSION} / \
API ${CMAKE_SYSTEM_VERSION} / ${CMAKE_ANDROID_ARCH_ABI} / \
Clang / c++14 support / libc++ static"
    "Unix Makefiles"
)

include("${CMAKE_CURRENT_LIST_DIR}/utilities/polly_common.cmake")

include("${CMAKE_CURRENT_LIST_DIR}/flags/cxx14.cmake") # before toolchain!

include("${CMAKE_CURRENT_LIST_DIR}/os/android.cmake")

I tried to build a minimal example:

#include <experimental/optional>
#include <iostream>

int main() {
    std::experimental::optional<int> b = 6;
    std::cout << b.value()  <<  std::endl;
    return 0;
}

but it builds just fine with the same toolchain.

I apologize, that I cannot post my code here. Any ideas what might be the problem?

1

There are 1 answers

0
Dan Albert On

Update to NDK r19 and just use std::optional. It's not experimental in C++17.