Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up C++11 (std::thread) for NDK with 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 Application.mk 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

I tried to change the 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??

Any help is appreciated!

like image 908
Wajih Avatar asked May 28 '14 11:05

Wajih


2 Answers

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.

like image 118
Alex Cohn Avatar answered Sep 27 '22 18:09

Alex Cohn


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

like image 42
Aqua Avatar answered Sep 27 '22 16:09

Aqua