std :: experimental ::与ndk / clang一起使用

时间:2019-05-09 16:11:25

标签: c++ cmake android-ndk c++14 c++-experimental

我正在尝试构建使用std::experimental::optional的项目。对于Linux,它可以很好地编译,但是对于android / ndk,编译器会抛出:

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

我正在使用polly工具链android-ndk-r17-api-24-armeabi-v7a-clang-libcxx14set(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")

我试图建立一个最小的例子:

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

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

但是它可以使用相同的工具链构建。

很抱歉,我无法在此处发布代码。有任何想法可能是什么问题吗?

1 个答案:

答案 0 :(得分:0)

更新为NDK r19,仅使用std::optional。在C ++ 17中不是实验性的。