本文介绍了Android NDK:如何在 Android.mk 中动态获取编译器架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

APP_ABI := all

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

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.

# 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?

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

 APP_ABI := armeabi armeabi-v7a mips x64

使用 Android.mk:

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)

但出现以下错误:

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

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

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

推荐答案

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

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

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

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

If you specify APP_ABI := armeabi-v7a armeabi mips x86 or APP_ABI := all in your Application.mk you will get each and every separate ABI value.

这篇关于Android NDK:如何在 Android.mk 中动态获取编译器架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 03:40