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

标签 c++ makefile android-ndk g++ ndk-build

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

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

[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

关于c++ - 为什么 NDK 编译器无法识别 LOCAL_CFLAGS 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32489291/

相关文章:

c++ - 将 vector 指针 move 到 C++ 中的 vector 派生类?

c++ - 如何要求 Linux g++ 正确编译另一个头文件中包含的头文件?

c - 使用 perl XS 链接到 C 共享库

android - 无法打开符号文件。错误 (20) : Not a directory

android - 如何构建 Android NDK 示例 : "bitmap-plasma"

c++ - 在终端 C++ 中从字符串中打印出 unicode 字符

c++ - 在现有的visual studio 2017中下载c++

c++ - 相机倒置 OpenGL

c - Cmake/Autotools 对于非标准编译器有用吗?

android - 如何在 Android 中执行 native 库?