Enable C++11 Support on Android

Enable C++11 support on Android

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)

Android NDK: Error: must be enabled with the -std=c++11 or -std=gnu++11 compiler options

Add "-std=c++11" to your CFLAGS in your Android.mk:

LOCAL_CFLAGS += -std=c++11

How to enable C++11/C++0x support in Eclipse CDT?

I found this article in the Eclipse forum, just followed those steps and it works for me. I am using Eclipse Indigo 20110615-0604 on Windows with a Cygwin setup.

  • Make a new C++ project
  • Default options for everything
  • Once created, right-click the project and go to "Properties"
  • C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++0x (or for newer compiler version -std=c++11 at the end . ... instead of GCC C++ Compiler I have also Cygwin compiler
  • C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__ (ensure to append and prepend two underscores) into "Name" and leave "Value" blank.
  • Hit Apply, do whatever it asks you to do, then hit OK.

There is a description of this in the Eclipse FAQ now as well: Eclipse FAQ/C++11 Features.

Eclipse setting

Eclipse image setting

Latest C++11 features with Android NDK

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

How do you enable C++11 syntax in Eclipse Neon?

  1. Right click on your project and click Properties
  2. Navigate to C/C++ General and Preprocessor Include Paths, Macros etc.
  3. Select the Providers tab, click on compiler settings row for the compiler you use.
  4. Add -std=c++11 to Command to get compiler specs.
  5. Apply changes.

Will look something like this:

${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11

How to change ndk setting from default C++ toolchain to C++14 after project is created?

You specify it in your app/build.gradle script.

android {
defaultConfig {
externalNativeBuild {
cmake {
cppFlags "-std=c++14"
}
}
}
}

Change cmake to ndkBuild depending on which method you're using.



Related Topics



Leave a reply



Submit