Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latest C++11 features with Android NDK

I am trying to use C++11 threading facilities with Android NDK, but not sure how to make it use the latest compilers.

I have Clang 3.2 and can build iOS apps. I wonder if there is a way to do it with Android NDK?

If not, then how should I build with gcc 4.8?

like image 615
Kimi Avatar asked Jun 17 '13 07:06

Kimi


People also ask

What can I do with Android NDK?

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

Which version of NDK should I use?

Dan Albert. The NDK version and the Android version you are targeting are orthogonal concepts. You should always be using the latest NDK for the best behavior (possibly N-1 if there's a bug in the latest stable, but that won't be the average case).

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.

What is difference between Android NDK and SDK?

Android provides Native Development Kit (NDK) to support native development in C/C++, besides the Android Software Development Kit (Android SDK) which supports Java. [TODO] more. NDK is a complex and advanced topics.


2 Answers

(I'm addressing the NDK version r9b) To enable C++11 support for all source code of the application (and so any modules included) make the following change in the Application.mk:

# use this to select gcc instead of clang
NDK_TOOLCHAIN_VERSION := 4.8
# OR use this to select the latest clang version:
NDK_TOOLCHAIN_VERSION := clang


# then enable c++11 extentions in source code
APP_CPPFLAGS += -std=c++11
# or use APP_CPPFLAGS := -std=gnu++11

Otherwise, if you wish to have C++11 support only in your module, add this lines into your Android.mk instead of use APP_CPPFLAGS

LOCAL_CPPFLAGS += -std=c++11

Read more here: http://adec.altervista.org/blog/ndk_c11_support/

like image 105
Mouze Avatar answered Oct 20 '22 00:10

Mouze


NDK revision 10 has the Clang 3.6 toolchain. Use it:

NDK_TOOLCHAIN_VERSION := clang3.6

or use the latest available Clang toolchain

NDK_TOOLCHAIN_VERSION := clang
like image 41
Sergey K. Avatar answered Oct 19 '22 23:10

Sergey K.