简体   繁体   English

控制Android NDK中的编译器标志?

[英]Controlling compiler flags in the Android NDK?

I know I can use LOCAL_CFLAGS to pass arguments to the compiler. 我知道我可以使用LOCAL_CFLAGS将参数传递给编译器。 However, ndk-build is inserting options after my LOCAL_CFLAGS , and therefore they take precedence. 但是, ndk-build是在我的LOCAL_CFLAGS之后插入选项,因此它们优先。 For example, I want to specify -Ofast , but ndk-build adds -O2 after my own flags, and since only the last option is the one that has any effect, I'm unable to test my code with certain optimization flags set. 例如,我想指定-Ofast ,但是ndk-build在我自己的标志之后添加-O2 ,并且因为只有最后一个选项是有效的那个,所以我无法使用某些优化标志集来测试我的代码。

Is there any way to either force my LOCAL_CFLAGS to be the last options on the build command, or to disable ndk-build from using certain flags? 有没有办法强制我的LOCAL_CFLAGS成为构建命令的最后一个选项,或禁用ndk-build使用某些标志?

For example, my LOCAL_CFLAGS is set to: 例如,我的LOCAL_CFLAGS设置为:

-Wall -Wno-psabi -Ofast -D CP_USE_DOUBLES=0 -D USE_CHIPMUNK

And the call to g++ that ndk-build makes is: ndk-buildg++的调用是:

/Library/Android/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/native-activity/Main.od -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-exceptions -fno-rtti -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Ijni -Ijni/Chipmunk/include/chipmunk -I/Library/Android/android-ndk-r8b/sources/android/native_app_glue -I/Library/Android/android-ndk-r8b/sources/cxx-stl/stlport/stlport -I/Library/Android/android-ndk-r8b/sources/cxx-stl//gabi++/include -Ijni -DANDROID -Wall -Wno-psabi -Ofast -D CP_USE_DOUBLES=0 -D USE_CHIPMUNK -Wa,--noexecstack -frtti -O2 -DNDEBUG -g -I/Library/Android/android-ndk-r8b/platforms/android-9/arch-arm/usr/include -c jni/Main.cpp -o ./obj/local/armeabi-v7a/objs/native-activity/Main.o

There's a lot in there, but specifically notice that it first specifies -Os , then there's my -Ofast , and then after that there's -O2 . 那里有很多,但特别注意它首先指定-Os ,然后是我的-Ofast ,然后是-O2 Why it specifies -Os if it's going to later say -O2 , I don't know, but I'm frustrated my -Ofast is being overridden. 为什么它指定-Os如果它稍后会说-O2 ,我不知道,但我很沮丧我的-Ofast被覆盖了。

Add

APP_CFLAGS += -Ofast

to your Application.mk. 到您的Application.mk。

It will not stop NDK from adding -O2 but it will place your flag after the NDK's. 它不会阻止NDK添加-O2但它会在NDK之后放置你的旗帜。 This works for me with NDK r8b. 这适用于NDK r8b。

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

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