添加&“-O0&"到cppFlags无法在android studio中禁用clang编译优化 [英] adding "-O0" to cppFlags fails to disable clang compile optimization in android studio

查看:102
本文介绍了添加&“-O0&"到cppFlags无法在android studio中禁用clang编译优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以调试模式构建应用程序,并且我注意到一些错误,指出父级无法评估:没有位置,值可能已被优化".因此,我尝试像这样在模块build.gradle中添加"-O0":

I am building my app in debug mode, and I notice some errors saying "parent failed to evaluate: no location, value may have been optimized out". Therefore, I try to add "-O0" in my module build.gradle like this:

externalNativeBuild {
    cmake {
        cppFlags "-O0 -frtti -fexceptions -std=c++11 -DANDROID_ARM_NEON=TRUE -mfloat-abi=softfp "
        abiFilters "armeabi-v7a"
    }
}

但是,添加"-O0"后仍然出现相同的错误.请问如何正确禁用编译器优化?我的android Studio版本是2.3.3,我的sdk工具版本是26.0.2,我的ndk版本是15.1.4

But still, the same error shows up after adding "-O0". May I ask how to disable compiler optimization properly? My android Studio version is 2.3.3, my sdk tool version is 26.0.2 and my ndk version is 15.1.4

推荐答案

您可以通过将以下内容添加到您的 CMakeLists.txt 中来覆盖构建标志:

You can override the build flags by adding the following to your CMakeLists.txt:

# Debug flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")

# Release flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")

要验证是否有效,请检查以下位置的构建输出:

To verify this has worked check build output in:

app/.externalNativeBuild/cmake/<buildconfig>/<architecture>/build.ninja

查找以 FLAGS 开头的行.这实际上并不会替换现有的编译器标志,而只是附加您的标志,并且这些标志具有优先权.

Look for a line starting with FLAGS. This doesn't actually replace the existing compiler flags it just appends your flags and these take precedence.

默认标志继承自 $ ANDROID_NDK/build/cmake/android.toolchain.cmake ,因此您可以直接编辑该文件,但是,如果更新NDK,这些更改将被覆盖.

The default flags are inherited from $ANDROID_NDK/build/cmake/android.toolchain.cmake so you could edit that file directly, however, if you update your NDK these changes will be overwritten.

这篇关于添加&amp;“-O0&amp;"到cppFlags无法在android studio中禁用clang编译优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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