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
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?
- Right click on your project and click Properties
- Navigate to C/C++ General and Preprocessor Include Paths, Macros etc.
- Select the Providers tab, click on compiler settings row for the compiler you use.
- Add -std=c++11 to Command to get compiler specs.
- 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
How to Make a Dialog Slide from Bottom to Middle of Screen in Android
How to Keep The Oauth Consumer Secret Safe, and How to React When It's Compromised
How to Pass Image Data from One Activity to Another Activity
How to Get Raw Preview Data from Camera Object at Least 15 Frames Per Second in Android
How to Create a Service Which Continuously Monitors App Usage Information
How to Develop Android App Completely Using Python
Overriding the Power Button in Android
Android- Phonegap/Webview Ignores Viewport Meta Tags
What's "Requestcode" Used for on Pendingintent
Best Way to Show a Loading/Progress Indicator
Android Rxjava 2 Junit Test - Getmainlooper in Android.Os.Looper Not Mocked Runtimeexception
Change The Background Color of a Pop-Up Dialog
Android Webview Jellybean -> Should Not Happen: No Rect-Based-Test Nodes Found
How to Create Android Project with Gradle from Command Line
Can an Android Device Act as an Ibeacon