How to compile C ++ 11 code using android ndk and eclipse?

I am using android NDK r8d and eclipse Juno. I am trying to compile C ++ code that uses C ++ 11, e.g. mutex , lock_guard , shared_ptr , etc. In an Android own 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 . They seem to work for them, but the explanation is not complete there, so I can't get it to work for me.

I added "NDK_TOOLCHAIN_VERSION=4.7" to the Application.mk file and "LOCAL_CFLAGS += -std=c++11" to Android.mk . However, it does not compile.

The link above says:

"Make sure that the path is included in the standard library (for example, / android -ndk-r8d / sources / cxx-stl / gnu-libstdc ++ / 4.7 / include) in the target settings."

How and where to insert it?

I also get errors in the Eclipse IDE (in the source code before compilation). I know that I have to define "__GXX_EXPERIMENTAL_CXX0X__" to solve them, but I just don't know where to put it.

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

+15
c ++ gcc c ++ 11 smart-pointers android-ndk
Mar 07 '13 at 11:04 on
source share
2 answers

Regarding your first question:

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

  • On the Include tab, add the appropriate directory, for example. / Android-NDK-R8d / sources / CXX-STL / wildebe-libstdC ++ / 4.7 / enable

Regarding your second question, I am also looking for an answer. It is completely incomprehensible how to define the macro GXX_EXPERIMENTAL_CXX0X in Eclipse.

Some say it should be β€œadded as a predefined macro for the indexer,” but it looks like we both couldn't find a way to implement this ...

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

+6
Mar 11 '13 at 11:12
source share

I find exporting the environment variable NDK_TOOLCHAIN_VERSION = 4.8 before I run eclipse can solve this problem.

Eclipse uses ndk by default toolchain version 4.6 if NDK_TOOLCHAIN_VERSION does not define, and gcc if this version does not support all future C ++ 11, such as multithreading, etc.

0
May 23 '15 at 14:35
source share



All Articles