【发布时间】:2015-11-07 15:14:06
【问题描述】:
我尝试在我的项目中使用 std::function,在这里和那里阅读 C++ 11 得到了很好的支持。然而,简单地使用 std::function 会使构建失败:
[armeabi] Compile++ thumb: MyAppNative <= MyAppNative.cpp
jni/MyAppNative.cpp: In function 'jint JNI_OnLoad(JavaVM*, void*)':
jni/MyAppNative.cpp:7:2: error: 'function' is not a member of 'std'
std::function<void()> func;
^
jni/MyAppNative.cpp:7:24: error: 'func' was not declared in this scope
std::function<void()> func;
^
make: *** [obj/local/armeabi/objs/MyAppNative/MyAppNative.o] Error 1
我的问题是:应该支持 std::function 吗?我已经看到它在标题中有条件地定义,具体取决于_STLP_USE_BOOST_SUPPORT。这正常吗?如果有人有兴趣测试,我附上了一个示例项目。
http://www.filedropper.com/cpp11-functional-issue
干杯
【问题讨论】:
-
您在构建时添加了
-std=c++11标志吗?使用哪个版本的 GCC? -
请参阅“如何设置运行时”中的 developer.android.com/ndk/guides/cpp-support.html。
-
是的,我确实添加了标志(您可以查看存档),我认为 GCC 版本是 4.8(至少在我更新到 r10e 进行测试之前)。 Christian> 谢谢,但这里没有提到 std::function 。我已经在使用 APP_STL := stlport_static(在我的可下载示例中),没有任何迹象表明此版本已降级。
-
@Brunni:为什么降级? AFAIK STLport 从未支持过 C++11。
-
Christian Hackl 是对的,你需要 gnustl_static 或 c++_static
标签: android c++ c++11 stl android-ndk