gpt4 book ai didi

安卓.mk : How to check if a module already exists

转载 作者:太空狗 更新时间:2023-10-29 16:30:33 28 4
gpt4 key购买 nike

我正在尝试为现有构建环境自动生成 Android.mk 文件。这个环境有许多相互链接的库,也可能链接到第 3 方库(如 boost)。

假设我有使用 boost 的 libA。我的目标是通过从 libB 文件夹运行 ndk-build 来构建 libAlibB

所以我为 libA 生成了这个 Android.mk:

LOCAL_PATH := $(call my-dir)

# Import boost
include $(CLEAR_VARS)
LOCAL_MODULE := boost_atomic
LOCAL_SRC_FILES := ../dev/libcpp/boost/1.60.1/lib/libboost_atomic.a
include $(PREBUILT_STATIC_LIBRARY)

# libA:
include $(CLEAR_VARS)
LOCAL_MODULE := libA
LOCAL_SRC_FILES := libA.cpp
LOCAL_C_INCLUDES := ../dev/libcpp/boost/1.60.1

# boost import:
LOCAL_CPPFLAGS += -DHAVE_CONFIG_H -fexceptions -frtti
LOCAL_STATIC_LIBRARIES += boost_atomic

# build libA:
include $(BUILD_SHARED_LIBRARY)

现在我有了使用 boostlibAlibBlibBAndroid.mklibA 非常相似,除了我添加了 libA 文件的导入作为下面:

# Import libA
include $(CLEAR_VARS)
LOCAL_MODULE := libA
include ../../libA/jni/Android.mk

当我尝试制作 libB 时,我被报告:

Android NDK: Trying to define local module 'boost_atomic' in ../../libA/jni/Android.mk.
Android NDK: But this module was already defined by ../../libA/jni/Android.mk.
B:/Android/android-ndk-r11b/build//../build/core/build-module.mk:34: *** Android
NDK: Aborting. . Stop.

有没有办法让我检查 boost_atomic 是否已经定义(比如 if (exists boost_atomic))以确保它只被定义一次?或者我应该为所有名称加上后缀(以 boost_system_for_libAboost_system_for_libB 结尾)以防止冲突?或者任何其他选择?

最佳答案

您有一个 NDK 函数 $(modules_get_list)。依靠它,您的 libA/jni/Android.mk 文件可能如下所示:

LOCAL_PATH := $(call my-dir)

include ../../boost/Android.mk

# libA:
include $(CLEAR_VARS)
LOCAL_MODULE := libA
LOCAL_SRC_FILES := libA.cpp

# boost import:
LOCAL_STATIC_LIBRARIES += boost_atomic

# build libA:
$(if $(call set_is_member,$(modules-get-list),$(LOCAL_MODULE)),\
,$(eval include $(BUILD_SHARED_LIBRARY)))

boost/Android.mk文件:

LOCAL_PATH := $(call my-dir)

# Import boost
include $(CLEAR_VARS)
LOCAL_MODULE := boost_atomic
LOCAL_SRC_FILES := ../dev/libcpp/boost/1.60.1/lib/libboost_atomic.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../dev/libcpp/boost/1.60.1
LOCAL_EXPORT_CPPFLAGS += -DHAVE_CONFIG_H -fexceptions -frtti
$(if $(call set_is_member,$(modules-get-list),$(LOCAL_MODULE)),\
,$(eval include $(PREBUILT_STATIC_LIBRARY))

最后,libB/jni/Android.mk:

LOCAL_PATH := $(call my-dir)

include ../../boost/Android.mk
include ../../libA/jni/Android.mk

# libB:
include $(CLEAR_VARS)
LOCAL_MODULE := libB
LOCAL_SRC_FILES := libB.cpp

# boost import:
LOCAL_STATIC_LIBRARIES += boost_atomic

# build libA:
$(if $(call set_is_member,$(modules-get-list),$(LOCAL_MODULE)),\
,$(eval include $(BUILD_SHARED_LIBRARY)))

我不希望对第 3 方预构建库(如 boost)有重复的定义,而是为每个库使用单独的 Android.mk 定义,并在任何时候包含必要的。这样一来,如果外部库更新,我就有一个地方可以更改。

更新:如果你不喜欢$(if …)语法,你可以使用

ifeq ($(filter $(modules-get-list),$(LOCAL_MODULE)),)
include $(BUILD_…_LIBRARY)
endif

相反。

关于安卓.mk : How to check if a module already exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40159015/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com