简体   繁体   English

在Android上启用C ++ 11支持

[英]Enable C++11 support on Android

如何将C ++ 11集成到Android中?

It appears the main answer here includes experimental support for C++11, and C++11 is not experimental anymore. 似乎这里的主要答案包括对C ++ 11的实验性支持,而C ++ 11不再是实验性的。

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支持(我将IDEA社区版本13用于Java东西),那么这就是我必须放入jni/Application.mk才能获得API 19(在OSX上)的C ++ 11支持的原因。 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 . 这里这里

First of all, you will need to ensure that your toolchain is "Cross GCC". 首先,您需要确保您的工具链是“跨GCC”。 Whilst it was the default on my Linux, it was not on my MacOSX Lion. 虽然这是我的Linux上的默认设置,但不是我的MacOSX Lion上的默认设置。

In order to do this, go to Project Properties > C/C++ Build > Tool Chain Editor . 为此,请转到“ 项目属性”>“ C / C ++构建”>“工具链编辑器” " Current toolchain " should be set to " Cross GCC ". 当前工具链 ”应设置为“ 跨GCC ”。 You might need to uncheck the box " Display compatible toolchains only ". 您可能需要取消选中“ 仅显示兼容工具链 ”框。

Then, add an option to LOCAL_CFLAGS in Android.mk : 然后,向Android.mk中的 LOCAL_CFLAGS添加一个选项:

LOCAL_CFLAGS := -std=gnu++11

We now need to inform Eclipse about where to find the corresponding new symbols (eg "std::unordered_map"). 现在,我们需要通知Eclipse有关在哪里可以找到相应的新符号(例如“ 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..."): 右键单击“ jni”>“属性”>“ C / C ++常规”->“路径和符号”->“符号”->“ GNU C ++” ,然后添加以下符号(通过单击“添加...”):

Name: __GXX_EXPERIMENTAL_CXX0X__
Value:

(ie let "Value" empty) (即让“值”为空)

You can also set this in your build.gradle file if you are using the gradle-experimental-plugin : 如果使用gradle-experimental-plugin,也可以在build.gradle文件中进行设置:

android.ndk {
    moduleName = "hello-android-jni"
    stl = "stlport_shared"
    cppFlags.add("-std=c++11")
}

With the latest gradle-experimental-plugin 0.8.0-alpha4 add to your app/build.gradle : 使用最新的gradle-experimental-plugin 0.8.0-alpha4添加到您的app / build.gradle中

model {
    android {
        ndk {
            moduleName "native"
            CFlags.add("-std=c11") // Enable C11 support
            ldLibs.add("log")
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM