1

I tried to use std::function in my project, having read here and there that C++ 11 is quite well supported. However simply using std::function makes the build fail:

[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

My question is: is std::function supposed to be supported? I've seen it conditionally defined in the header, depending on _STLP_USE_BOOST_SUPPORT. Is that normal? I have attached a sample project if anyone is interested in testing.

http://www.filedropper.com/cpp11-functional-issue

Cheers

7
  • You do add the -std=c++11 flag when building? Which version of GCC is used? Commented Nov 7, 2015 at 15:16
  • See developer.android.com/ndk/guides/cpp-support.html at "How to set your runtime". Commented Nov 7, 2015 at 15:38
  • Yes I did add the flag (you can take a look at the archive), the GCC version is 4.8 I think (it was at least, before I updated to r10e for testing). Christian> Thanks, but std::function is nowhere to be mentioned here. I'm using APP_STL := stlport_static already (in my downloadable sample), and nothing indicates that this version is downgraded.
    – Brunni
    Commented Nov 7, 2015 at 15:45
  • 2
    @Brunni: Why downgraded? AFAIK STLport has never had C++11 support. Commented Nov 7, 2015 at 16:10
  • 1
    Christian Hackl is right, you need gnustl_static or c++_static
    – Alex Cohn
    Commented Nov 7, 2015 at 17:41

2 Answers 2

1

STLport, which you seem to be using, has never had C++11 support.

See developer.android.com/ndk/guides/cpp-support.html at "How to set your runtime" and choose a different one (gnustl_static or c++_static).

3
  • It would be better to copy paste how to configure the runtime instead of linking to an external size. Like Brunni did, his answer helped me much faster.
    – mxmlnkn
    Commented Aug 19, 2016 at 0:49
  • My Application.mk APP_OPTIM := release APP_PLATFORM := android-14 APP_STL := c++_static APP_CFLAGS += -std=c++11 APP_CPPFLAGS += -frtti APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -DANDROID APP_CPPFLAGS += -std=gnu++0x LOCAL_CPP_FEATURES += exceptions APP_ABI := all APP_MODULES :=ndksampleapp NDK_TOOLCHAIN_VERSION := 4.9 but still I am getting error 'std::function' has not been declared
    – AdiAtAnd
    Commented Sep 14, 2016 at 2:34
  • Is it like stoi I will be able to get through c++_static and function through gnustl_static, coz if I replace with gnustl it is crying for stoi. I am new to this. This can sound silly or wrong question to some people. Please help.
    – AdiAtAnd
    Commented Sep 14, 2016 at 2:41
1

Ok so thanks to Christian and Alex, the answer is indeed to change your Application.mk so that it references gnustl_static.

APP_STL := gnustl_static

Thank you all!

3
  • The unwritten rules of SO courtesy would suggest that you let Christian Hackl to post his comment as answer.
    – Alex Cohn
    Commented Nov 9, 2015 at 7:38
  • Yup I'm not used to it yet, but it clearly felt wrong :) Well for now I'll just cancel the answer mark and validate it when Christian Hackl posts an answer to this topic!
    – Brunni
    Commented Nov 13, 2015 at 12:42
  • @Brunni: No problem. I did not realise that my comment would actually help you so much that you'd consider it an answer :) I've turned it into an actual answer now. Commented Nov 13, 2015 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.