Setting up C++11 (std::thread) for NDK with ADT/Eclipse

前端 未结 3 1221
心在旅途
心在旅途 2020-12-19 03:33

I have been trying to use C++11. I am developing an android project and i want to use std::mutex. Along with OpenCV But no matter what I do, I just cant seem to fix the

相关标签:
3条回答
  • 2020-12-19 04:17

    If you upgrade the NDK or install a fresh version of Android Studio (2.1 at time of writing) and have Android Studio download the NDK for you you will get revision 12 - which has a lot of the std:: defines not defined in \ndk-bundle\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a\include\bits\c++config.h - ones relevant for threading being such as _GLIBCXX_HAS_GTHREADS which hides the thread class in "thread" for example.

    It says that after revision 10e that gcc is deprecated. And with this all the defines as mentioned - which thoroughly buggered our thread dependant JNI code.

    Clang as suggested in other posts is not a solution for us as it amongst other things seems not to support thead_local for example. The solution is to revert back to revision 10e - which you can find at:

    dl.google.com/android/ndk

    Extract the package and copy into the sdk/ndk-bundle directory - make sure you delete the original revision 12 first.

    0 讨论(0)
  • 2020-12-19 04:22

    Support for std::thread is a bit special. The issue is addressed, for example, in this article by Binglong. The article is really short, but it can be summarized in one sentence:

    You cannot use the (default) gcc 4.6 toolchain if you want to #include <thread> or #include <mutex>.

    So, please add NDK_TOOLCHAIN_VERSION=4.8 or NDK_TOOLCHAIN_VERSION=clang to your Application.mk.

    For ADT to rebuild its Index correctly, see Android NDK build, Method could not be resolved or Eclipse compiles successfully but still gives semantic errors.

    0 讨论(0)
  • 2020-12-19 04:29

    In Android.mk add LOCAL_CPPFLAGS := -std=c++11 -D __cplusplus=201103L then rebuild your project (for reconfiguring compiler). After rebuilding, your project automatically adds needed stl path into Path and Symbols

    0 讨论(0)
提交回复
热议问题