如何为 Android Studio 启用 C++11? [英] How to enable C++11 for Android Studio?

查看:96
本文介绍了如何为 Android Studio 启用 C++11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android studio 1.3.2+ndk-r11b-windows-x86_64 并尝试使用本机代码和 C++11 功能(share_ptr、weak_ptr 等)构建项目,但遇到了一些错误.例如:

I'm using Android studio 1.3.2+ndk-r11b-windows-x86_64 and try to build project with native code and C++11 features (share_ptr, weak_ptr and etc.) but got some errors. For example:

错误:(22, 6) 错误:命名空间std"中的shared_ptr"未命名模板类型

Error:(22, 6) error: 'shared_ptr' in namespace 'std' does not name a template type

问题是:如何在Android Studio+NDK中使用C++11?

The issue is: how to use C++11 with Android Studio+NDK?

附言我将标志 cppFlags.add ("-std=c++11") 添加到build.gradle"

p.s. I added flag cppFlags.add ("-std=c++11") into "build.gradle"

 android.ndk {
        moduleName = "game"
        cppFlags.addAll(["-I${file("src/main/jni/native_app_glue")}".toString(),
                         "-I${file("src/main/jni")}".toString(),
                         "-I${file("src/main/jni/data")}".toString()])
        cppFlags.add ("-std=c++11")
        ldLibs.addAll(["android", "EGL", "GLESv2", "OpenSLES", "log"])
        stl        = "stlport_static"
}

但似乎没有用.

推荐答案

在应用程序的 build.gradle 文件中,我转到 android -> defaultConfig -> externalNativeBuild -> cmake 并从中编辑 cppFlags 参数

On build.gradle file of the App I go to android -> defaultConfig -> externalNativeBuild -> cmake and I edit the cppFlags parameter from this

cppFlags ""

到这里

cppFlags "-std=c++11"

这篇关于如何为 Android Studio 启用 C++11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆