为什么 NDK 编译器无法识别 LOCAL_CFLAGS 定义?

Why does NDK compiler not recognize a LOCAL_CFLAGS definition?

我有一些预先存在的代码,我正在尝试将其编译到 NDK 库中。有一个简单的#ifndef 我需要正确执行,但在我的 Android.mk 中,无法识别我用 LOCAL_CFLAGS 定义的 var。它认为这是一个命令行选项

当我 运行 ndk-build 使用 NDK_LOG 选项时,它都可以正常编译,直到我看到这个:

[armeabi-v7a] Compile++ thumb: NDKImageProcessor <= NDKImageProcessor.cpp
arm-linux-androideabi-g++: error: unrecognized command line option '-WINONLY=1'
make: *** [obj/local/armeabi-v7a/objs/NDKImageProcessor/NDKImageProcessor.o] Error 1

我只是想将以下内容包含在编译中:

#ifndef WINONLY
    #import <CoreGraphics/CGGeometry.h>
#endif

Android.mk 非常简单:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := NDKImageProcessor

LOCAL_SRC_FILES := NDKImageProcessor.cpp
LOCAL_SRC_FILES += ../../../../SharedSrc/Image.cpp

LOCAL_LDLIBS := -llog

LOCAL_CFLAGS := -WINONLY=1

include $(BUILD_SHARED_LIBRARY)

如果我只是不添加 LOCAL_CFLAGS 行,编译器会尝试编译该 iOS 代码,这显然是不行的。

来自the GCC documentation(如果你用Clang的话应该是一样的):

-D name
Predefine name as a macro, with definition 1.

-D name=definition
The contents of definition are tokenized and processed as if they appeared during translation phase three in a ‘#define’ directive. In particular, the definition will be truncated by embedded newline characters.

因此,要使用值 1 定义 WINONLY,您将使用:

LOCAL_CFLAGS := -DWINONLY=1

或者干脆

LOCAL_CFLAGS := -DWINONLY