15

I'm using android NDK r8d, and eclipse Juno. I'm trying to compile C++ code which uses C++11 stuff like mutex, lock_guard, shared_ptr, etc. in a native android project in eclipse.

I get errors like:

"error: 'shared_ptr' is not a member of 'std'"

"fatal error: mutex: No such file or directory"

I came across a similar question here. It seems to work for them, but the explanation there is not complete so I can't get it to work for me.

I added "NDK_TOOLCHAIN_VERSION=4.7" to the Application.mk and "LOCAL_CFLAGS += -std=c++11" to Android.mk file. Still, it doesn't compile.

In the link above it says:

"Be sure that the standard library include path (like /android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) is in the target settings."

How and where do I insert it?

I also get errors in eclipse IDE (on the source, before compiling). I know I should define "__GXX_EXPERIMENTAL_CXX0X__" to resolve them but I just don't know where to put it.

So, if someone could post an answer with a full explanation of how to compile and make eclipse work with C++11 it would be great.

Community
  • 1
  • 1
DeathlessHorsie
  • 161
  • 1
  • 1
  • 7
  • Read the NDK doc, it's not possible. – Jaffa Mar 07 '13 at 11:06
  • http://stackoverflow.com/questions/14532057/smart-pointers-not-working-with-android-ndk-r8 it seems that they managed it – DeathlessHorsie Mar 07 '13 at 11:08
  • which compiler are you using for c++? – naxchange Mar 08 '13 at 11:42
  • 1
    @naxchange I'm using the toolchain included with the Android NDK which I believe is gcc/g++. As I wrote, I set it to`"NDK_TOOLCHAIN_VERSION=4.7"` . There's a question about it [here](http://stackoverflow.com/questions/6602929/which-compiler-does-android-ndk-use). – DeathlessHorsie Mar 09 '13 at 13:09

2 Answers2

6

Regarding your first question:

  1. Go to Project > Properties > C/C++ General / Paths and Symbols

  2. In the "Includes" tab, add the proper directory, e.g. /android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include

Regarding your second question, I'm also looking for an answer. It is absolutely not clear how to define the GXX_EXPERIMENTAL_CXX0X macro in Eclipse.

Some say that it should be "added as a predefined macro to the indexer", but it looks like we both could not find a way to implement that...

I have read elsewhere that it should be added to "C/C++ General / Paths and Symbols / Symbols / GNU C++" but I can't find the "Symbols / GNU C++" part in my version of Indigo.

Ariel Malka
  • 15,697
  • 6
  • 31
  • 33
  • I use eclipse Juno and I also don't have the "Symbols / GNU C++" part, and without defining "__GXX_EXPERIMENTAL_CXX0X__" the indexer wont recognize the c++11 stuff. Did you managed to compile your code with the ndk? – DeathlessHorsie Mar 12 '13 at 13:49
  • Yes, the (C++11) code compiles fine with the NDK. The problem is only at the level of indexing inside Eclipse. – Ariel Malka Mar 17 '13 at 13:16
  • 2
    For the problem of fixing the indexer in Eclipse Juno, I posted a work-around hack at "http://stackoverflow.com/questions/9375708/eclipse-indexer-errors-when-using-stl-with-android-ndk/15782177#15782177" – Shervin Emami Apr 03 '13 at 08:19
0

I find export an environment variable NDK_TOOLCHAIN_VERSION=4.8 before i start eclipse can solve this problem.

Eclipse use ndk's default toolchain version 4.6, if NDK_TOOLCHAIN_VERSION is not define, and gcc witch this version does not support all c++11's future like multithread and so on.