Android NDK和Crystax无法识别STD :: Index_Sequence

Android NDK and CrystaX doesn't recognize std::index_sequence

本文关键字:STD Index Sequence 识别 NDK Crystax Android      更新时间:2023-10-16

我尝试编译我从cppreferency.com复制的代码

#include <iostream>
#include <tuple>
#include <utility>
template<typename Func, typename Tup, std::size_t... index>
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
{
    return func(std::get<index>(std::forward<Tup>(tup))...);
}
template<typename Func, typename Tup>
decltype(auto) invoke(Func&& func, Tup&& tup)
{
    constexpr auto Size = std::tuple_size<typename std::decay<Tup>::type>::value;
    return invoke_helper(std::forward<Func>(func),
                         std::forward<Tup>(tup),
                         std::make_index_sequence<Size>{});
}
void foo(int a, const std::string& b, float c)
{
    std::cout << a << " , " << b << " , " << c << 'n';
}

我的android.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    :=test
LOCAL_SRC_FILES :=../../test.cpp
LOCAL_STATIC_LIBRARIES := c++_static
LOCAL_CFLAGS := -std=c++14
include $(BUILD_STATIC_LIBRARY)

我的application.mk:

APP_MODULES      := test
APP_OPTIM        := release
APP_ABI          := armeabi armeabi-v7a mips x86
NDK_TOOLCHAIN_VERSION=clang
APP_STL := c++_static

使用NDK R13B,我遇到了此错误:

jni/../../test.cpp:6:10: warning: 'decltype(auto)' type specifier is a C++14 extension [-Wc++14-extensions]
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
         ^
jni/../../test.cpp:6:59: error: no type named 'index_sequence' in namespace 'std'
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
                                                     ~~~~~^
jni/../../test.cpp:6:73: error: expected ')'
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
                                                                        ^
jni/../../test.cpp:6:29: note: to match this '('
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
                            ^
jni/../../test.cpp:6:1: error: deduced return types are a C++14 extension
decltype(auto) invoke_helper(Func&& func, Tup&& tup, std::index_sequence<index...>)
^
jni/../../test.cpp:12:10: warning: 'decltype(auto)' type specifier is a C++14 extension [-Wc++14-extensions]
decltype(auto) invoke(Func&& func, Tup&& tup)
         ^
jni/../../test.cpp:12:1: error: deduced return types are a C++14 extension
decltype(auto) invoke(Func&& func, Tup&& tup)
^
jni/../../test.cpp:17:31: error: no member named 'make_index_sequence' in namespace 'std'
                         std::make_index_sequence<Size>{});
                         ~~~~~^
jni/../../test.cpp:17:55: error: initializer list cannot be used on the right hand side of operator '>'
                         std::make_index_sequence<Size>{});
                                                      ^~~
jni/../../test.cpp:28:5: error: no matching function for call to 'invoke'
    invoke(foo, args);

我还尝试使用Crystax 10.3.2并获得相同的错误。看来我的标志-STD = C 14似乎没有生效。关于申请(自动),自动返回值和index_ sequence的错误投诉。所有都是C 14个功能。有建议吗?我尝试运行ndk-build v = 1,这是详细的输出

F:/Library/android-ndk-r13b/build//../toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -MMD -MP -MF ./obj/local/armeabi/objs/test/__/__/test.o.d -gcc-toolchain F:/Library/android-ndk-r13b/build//../toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -no-canonical-prefixes -fno-integrated-as -g -target armv5te-none-linux-androideabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -DNDEBUG  -IF:/Library/android-ndk-r13b/build//../sources/cxx-stl/llvm-libc++/include -IF:/Library/android-ndk-r13b/build//../sources/cxx-stl/llvm-libc++/../../android/support/include -IF:/Library/android-ndk-r13b/build//../sources/cxx-stl/llvm-libc++abi/include -Ijni -DANDROID -std=c++14 -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11     -isystem F:/Library/android-ndk-r13b/build//../platforms/android-9/arch-arm/usr/include -c  jni/../../test.cpp -o ./obj/local/armeabi/objs/test/__/__/test.o

我看到-STD = C 14和-STD = C 11均指定。也许-std = C 11优先?我不是从哪里来的。

我找到了解决方案,我只需要在application.mk中指定-std = c 14,而不是在android.mk中。所以现在,android.mk是

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    :=test
LOCAL_SRC_FILES :=../../test.cpp
LOCAL_STATIC_LIBRARIES := c++_static
include $(BUILD_STATIC_LIBRARY)

和application.mk:

APP_MODULES      := test
APP_OPTIM        := release
APP_ABI          := armeabi armeabi-v7a mips x86
NDK_TOOLCHAIN_VERSION=clang
APP_STL := c++_static
APP_CPPFLAGS += -std=c++14