Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile c++11 code with android ndk and eclipse?

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.

like image 358
DeathlessHorsie Avatar asked Mar 07 '13 11:03

DeathlessHorsie


People also ask

What compiler does Android NDK use?

Code written in C/C++ can be compiled to ARM, or x86 native code (or their 64-bit variants) using the Android Native Development Kit (NDK). The NDK uses the Clang compiler to compile C/C++. GCC was included until NDK r17, but removed in r18 in 2018.

Is NDK a compiler?

The NDK itself invokes a customized cross-compiler built on the arm-eabi-gcc compiler.

Is NDK open source?

OpenJDK has the same code as OracleJDK, depending on what provider you're using. The key difference (as stated above) is that OpenJDK is an open source java development kit, whereas Oracle JDK is closed source.


1 Answers

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.

like image 153
Ariel Malka Avatar answered Oct 10 '22 05:10

Ariel Malka