Configuring C ++ 11 (std :: thread) for NDK using ADT / Eclipse

I am 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 can't fix the Type 'mutex' could not be resolved error.

I tried to follow the instructions that I found in SO and other places. LINK1 LINK2 LINK3 link4

  • ADT v22.3.0-887826
  • Installed C / C ++ Compilers (CDT)

After so many training lessons, he became a real mess. Therefore, I will explain the current settings.

  • Project> Properties> C / C ++ Build> Tool Chain Editor
    • The current tool chain is "Cross GCC"
    • Current Builder - "Android Builder"
  • Project> Properties> C / C ++ Build> Discovery Options

    • The compiler call command is "gcc"
    • Compilation Expressions Compilter -E -P -v -dD "$ {plugin_state_location} /specs.c -std = C ++ 11"
  • Project> C / C ++ General> Outlines and Symbols> Symbols Tab

    • Character = __cplusplus and value = 1

In my Application.mk file I have

 APP_STL := gnustl_static APP_USE_CPP0X := true APP_CPPFLAGS := -std=c++11 -frtti -fexceptions APP_ABI := armeabi-v7a APP_PLATFORM := android-8 

I tried changing the value of the cplusplus symbol to 201103L and tried __GXX_EXPERIMENTAL_CXX0X with an empty value

But nothing works, what am I doing wrong?

Any help is appreciated!

+7
android eclipse c ++ 11 android-ndk jni
source share
3 answers

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

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

So 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, the method cannot be resolved or Eclipse compiles successfully, but still gives semantic errors .

+9
source share

In Android.mk add LOCAL_CPPFLAGS := -std=c++11 -D __cplusplus=201103L , then rebuild your project (to reconfigure the compiler). After restoration, your project automatically adds the necessary stl path to the Path and symbols

+2
source share

If you upgrade the NDK or install the new version of Android Studio (2.1 at the time of writing) and Android Studio download the NDK for you, you will get revision 12 - which has a lot of std :: define not defined in \ ndk-bundle \ sources \ cxx-stl \ gnu-libstdC ++ \ 4.9 \ libs \ armeabi-v7a \ include \ bits \ C ++ config.h - related to streaming, such as _GLIBCXX_HAS_GTHREADS, which hides the class of the stream in the "stream", for example.

It says that after the 10th revision, gcc is out of date. And with that, all the definitions, as mentioned, that carefully distort our thread-specific JNI code.

Clang, as suggested in other posts, is not a solution for us, because, among other things, it seems that this is not support for thead_local. The solution is to go back to revision 10e, which you can find at:

dl.google.com/android/ndk

Extract the package and copy it to the sdk / ndk-bundle directory - first uninstall the original version 12.

0
source share

All Articles