Configuración de C++11 (std::thread) para NDK con ADT/Eclipse

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 Type 'mutex' could not be resolved error.

I have tried following the tutorials i found on SO and other places. LINK1 LINK2 LINK3LINK4

  1. ADT v22.3.0-887826
  2. Installed C/C++ compilers (CDT)

Following so many tutorials, it has become a real mess now. So I will explain my current settings

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

    • Compiler invocation command is "gcc"
    • Compilter Invocation argments are -E -P -v -dD "${plugin_state_location}/specs.c -std=c++11"
  • Project > C/C++ General > Paths and Symbols > # Symbols tab

    • Symbol = __cplusplus and Value = 1

In my file I have the following

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

Traté de cambiar el cplusplus symbol's value to 201103L and tried __GXX_EXPERIMENTAL_CXX0X with an empty value

But nothing seems to work, What am I doing wrong??

Cualquier ayuda es apreciada!

preguntado el 28 de mayo de 14 a las 12:05

Is the problem simply an error highlighted by Eclipse, or does your build fail as well? Eclipse is buggy with C++11. -

Posible duplicado de Compilación de Android NDK, no se pudo resolver el método. Either way, you don't need CDT; you must install NDK though. -

No creo que "__cplusplus and Value = 1" is correct; the value should be at least 201103L for C++11 in my opinion. But I think you really shouldn't mess with the value __cplusplus. Now, what does "But nothing seems to work" mean? In short, please answer Steve's question. -

Una cosa más: Did you rebuild the index? -

What is the actual version of GCC you're using? If __cplusplus == 1, then it's quite likely too old a version. -

3 Respuestas

Apoyo a 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 para usted

For ADT to rebuild its Home correctamente, ver Compilación de Android NDK, no se pudo resolver el método or Eclipse compila con éxito pero aún da errores semánticos.

contestado el 23 de mayo de 17 a las 13:05

So what about the "include" sources where from tutorials I see cxx-stt/4.6 sort of stuff. Does this mean I have to change the include sources too? Probably yes, only then will your answer work, right? - wajih

There are probably different workarounds for the problem with Indexador. Maybe your approach is good, too. - Alex Cohn

Yes I have! Finally it has worked! Man was this so tough to nail. I had to restart eclipse, which took me 3 hours to figure out :) But all is working. - wajih

As of 2018-15-01, the link to the Binglong article leads to a wall that states that the article in question is private, thus rendering it unaccessible to pretty much everyone who has not been given privileges by the article's author. - Adrien

@Adrien, thanks for letting know. At any rate, I did post the summary of that article. Note that it isn't relevant these days: current NDK r16 supports C++11 and even C++17, but gcc toolchain is going away in the next release. Also, eclipse has been deprecated for many years now. - Alex Cohn

In 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

respondido 31 mar '16, 07:03

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:

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

Respondido 29 Abr '16, 12:04

according to NDK bugtracker this issue has been fixed - ls.illarionov

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.