AndroidStudio C++ Compiler Options

eyal 09/05/2017. 2 answers, 83 views
c++ android-studio android-studio android-ndk android-ndk jni

While trying to run my code, which is include C++ files I get the following error -

Error:(32, 2) error: This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

How it can be solved? This is my first project that involved with C++ files.

Asu 11/06/2016
You must enable "the -std=c++11 or -std=gnu++11 compiler options."
1 Christian Hackl 11/06/2016
Learning C++ on Android is a very bad idea. Anyway, you must somehow make your IDE pass the correct flags to the compiler in order to use C++11 features and/or use a compiler for which C++11 is no longer experimental. I hear there's some "Customize C++ Support" button or dropdown menu somewhere in the UI which can do that for you.
eyal 11/06/2016
I know i have to use -std=c++11 or -std=gnu++11 but how can i config that?
Michael 11/06/2016
There are multiple ways of building native code from Android Studio, and I don't see any mention of which one you're using. If you've got an file you could add any flags you want in there to LOCAL_CPPFLAGS. Otherwise you probably need to use some sort of cppFlags property in your build.gradle file.

2 Answers

eyal 11/06/2016.

I have rebuild my project and use C++11 instead of ToolChain Default in Customize C++ Support page. I think it is a dirty way for solving this problem.

Alex Cohn 07/30/2017
Maybe 'ToolChain Default' is not the perfect way to present one of the choices, but this is the clean way to deal with this problem. C++ has different not exactly compatible 'modes', e.g. C++11 and C++13, and it is your responsibility to choose the appropriate dialect.

eyal 11/07/2016.

In app's build gradle under android -> defaultConfig you can add / change the following

externalNativeBuild {
        cmake {
            cppFlags "-std=c++11"

Related questions

Hot questions


Popular Tags