Android NDK:如何在Android.mk中动态获取编译器架构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12614417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:12:12  来源:igfitidea点击:

Android NDK: How to get compiler architecture in Android.mk dynamically

androidandroid-ndk

提问by LuxuryMaster

I'm trying to configure Android.mk to cross compile native code to support different chipset namely armeabi, mips, and x86. I know I can configure Application.mk in the following way to compile the source code for different chip set:

我正在尝试将 Android.mk 配置为交叉编译本机代码以支持不同的芯片组,即 armeabi、mips 和 x86。我知道我可以通过以下方式配置 Application.mk 来编译不同芯片组的源代码:

APP_ABI := all

This will trigger Android-NDK's build script to compile the source code for all the chipsets. However, I want to dynamically tell Android.mk to look for different static library dependencies compiled with different chip set.

这将触发 Android-NDK 的构建脚本来编译所有芯片组的源代码。但是,我想动态地告诉 Android.mk 查找使用不同芯片组编译的不同静态库依赖项。

# Get the architecture info
ARCH := ????

include $(CLEAR_VARS)
LOCAL_MODULE:= mylib
LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)

Is this possible to do? If so, can anyone advice how to do so?

这是可能的吗?如果是这样,任何人都可以建议如何这样做吗?

Update: I tried something like this in Application.mk:

 APP_ABI := armeabi armeabi-v7a mips x64

with Android.mk:

# Get the architecture info
ARCH := $(APP_ABI)

include $(CLEAR_VARS)
LOCAL_MODULE:= mylib
LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)

but it errors with the following:

 The LOCAL_SRC_FILES for a prebuilt static library should only contain one item

which makes sense. I want to pass APP_ABI := all in Application.mk and be able to dynamically reference it. Any ideas?

更新:我在 Application.mk 中尝试过这样的事情:

 APP_ABI := armeabi armeabi-v7a mips x64

使用 Android.mk:

# Get the architecture info
ARCH := $(APP_ABI)

include $(CLEAR_VARS)
LOCAL_MODULE:= mylib
LOCAL_SRC_FILES:= build/lib/libxxx_$(ARCH).a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)

但它出现以下错误:

 The LOCAL_SRC_FILES for a prebuilt static library should only contain one item

这是有道理的。我想在 Application.mk 中传递 APP_ABI := all 并能够动态引用它。有任何想法吗?

采纳答案by Sergey K.

There is TARGET_ARCHvariable that holds the value of the current ABI being built. You can use it the following way:

有一个TARGET_ARCH变量保存当前正在构建的 ABI 的值。您可以通过以下方式使用它:

ifeq ($(TARGET_ARCH),x86)
    LOCAL_CFLAGS   := $(COMMON_FLAGS_LIST)
else
    LOCAL_CFLAGS   := -mfpu=vfp -mfloat-abi=softfp $(COMMON_FLAGS_LIST)
endif

If you specify APP_ABI := armeabi-v7a armeabi mips x86or APP_ABI := allin your Application.mkyou will get each and every separate ABI value.

如果您指定APP_ABI := armeabi-v7a armeabi mips x86APP_ABI := all在您Application.mk将获得每个单独的 ABI 值。

回答by nneonneo

Check TARGET_ARCH_ABI:

检查TARGET_ARCH_ABI

ifeq($(TARGET_ARCH_ABI), armeabi-v7a)
  # v7a-specific stuff
endif