Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable C++11 support on Android

Tags:

c++

android

c++11

How do I integrate C++11 into Android?

like image 836
JonasVautherin Avatar asked Mar 25 '13 13:03

JonasVautherin


People also ask

Can I use C++ on Android?

The Android Native Development Kit (NDK): a toolset that allows you to use C and C++ code with Android, and provides platform libraries that allow you to manage native activities and access physical device components, such as sensors and touch input.

What C++ compiler does Android use?

libc++ LLVM's libc++ is the C++ standard library that has been used by the Android OS since Lollipop, and as of NDK r18 is the only STL available in the NDK.

What is native library in Android?

Android applications can contain compiled, native libraries. Native libraries are code that the developer wrote and then compiled for a specific computer architecture. Most often, this means code that is written in C or C++.


2 Answers

It appears the main answer here includes experimental support for C++11, and C++11 is not experimental anymore.

If you're using command line NDK support (I use IDEA community edition 13 for the Java stuff), then this is what I had to put in my jni/Application.mk to get C++11 support with API 19 (on OSX ML):

NDK_TOOLCHAIN_VERSION := 4.8 # APP_STL := stlport_shared  --> does not seem to contain C++11 features APP_STL := gnustl_shared  # Enable c++11 extentions in source code APP_CPPFLAGS += -std=c++11 

Derived from here and here.

like image 65
scorpiodawg Avatar answered Sep 22 '22 01:09

scorpiodawg


First of all, you will need to ensure that your toolchain is "Cross GCC". Whilst it was the default on my Linux, it was not on my MacOSX Lion.

In order to do this, go to Project Properties > C/C++ Build > Tool Chain Editor. "Current toolchain" should be set to "Cross GCC". You might need to uncheck the box "Display compatible toolchains only".

Then, add an option to LOCAL_CFLAGS in Android.mk:

LOCAL_CFLAGS := -std=gnu++11 

We now need to inform Eclipse about where to find the corresponding new symbols (e.g. "std::unordered_map"). Go to Right Click on "jni" > Properties > C/C++ General -> Paths and Symbols -> Symbols -> GNU C++, and add the following symbol (by clicking "Add..."):

Name: __GXX_EXPERIMENTAL_CXX0X__ Value: 

(i.e. let "Value" empty)

like image 39
JonasVautherin Avatar answered Sep 21 '22 01:09

JonasVautherin