我尝试编译从cppreference.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似乎没有生效。关于decltyp(自动),自动返回值和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优先?我不知道它来自哪里。
答案 0 :(得分:0)
我找到了解决方案,我只需要在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