没有规则使目标 NDK

2022-09-02 20:25:57

我正在编译本机源代码,并使用.a libs添加依赖项以及具有以下结构的相对头文件。

/jni/

Android.mk

LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)

include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog
LOCAL_MODULE    := ndk1
LOCAL_SRC_FILES := native.c
LOCAL_STATIC_LIBRARY := mschema 
include $(BUILD_SHARED_LIBRARY)

native.c

/jni/prereqs/

Android.mk

LOCAL_PATH := $(call my-dir)

include $(call all-subdir-makefiles)

include $(CLEAR_VARS)

--用于调用子文件夹 mk 文件

/jni/prereqs/mschema/

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    :=mschema
LOCAL_SRC_FILES :=libmschema.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

include $(PREBUILT_STATIC_LIBRARY)

libmschema.a

/jni/prereqs/mschema/include

头文件。(.h)

但是在尝试 ndk 构建 (NDK5) 时,我遇到了以下错误。

marcos@marcos-AY675AA-AC4-s5320br:~/dev/workspace/rmsdk.native.wraper$ ndk-buildmake:
 *** No rule to make target `/home/marcos/dev/workspace/rmsdk.native.wraper/jni/prereqs/mschema/native.c', needed by `/home/marcos/dev/workspace/rmsdk.native.wraper/obj/local/armeabi/objs/ndk1/native.o'.  Stop.

在键入时,我注意到错误是关于/home/marcos/dev/workspace/rmsdk.native.wraper/jni/native.c',我的make文件中有什么问题?/home/marcos/dev/workspace/rmsdk.native.wraper/jni/prereqs/mschema/native.c' and actually this file is under

通过将第一个 Android.mk 更改为以下内容,可以避免此问题:

LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
LOCAL_PATH :=/home/marcos/dev/workspace/rmsdk.native.wraper/jni
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE    := ndk1
LOCAL_SRC_FILES := native.c
LOCAL_STATIC_LIBRARY := mschema
include $(BUILD_SHARED_LIBRARY)

但它看起来不对劲。有没有更好的方法?


答案 1

从 NDK 5 中的文档开始,解决方案是创建一个局部变量。

my-dir 返回最后一个包含的 Makefile 的路径,该路径通常是当前 Android.mk 的目录。这对于在 Android.mk 开始时定义LOCAL_PATH非常有用,例如:

    LOCAL_PATH := $(call my-dir)

IMPORTANT NOTE: Due to the way GNU Make works, this really returns
the path of the *last* *included* *Makefile* during the parsing of
build scripts. Do not call my-dir after including another file.

所以。。为了解决这个问题,我将我的 Android.mk 更改为以下内容。

 LOCAL_PATH := $(call my-dir)
 MY_PATH := $(LOCAL_PATH)
 include $(call all-subdir-makefiles)

 include $(CLEAR_VARS)

 LOCAL_PATH := $(MY_PATH)

 LOCAL_LDLIBS := -llog -ldl
 LOCAL_MODULE    := rmsdk
 LOCAL_SRC_FILES := native.c

 include $(BUILD_SHARED_LIBRARY)

它的工作原理。


答案 2

我认为在包含子生成文件之后定义本地路径是正确的。

LOCAL_PATH := $(call my-dir)
 MY_PATH := $(LOCAL_PATH)
 include $(call all-subdir-makefiles)

 include $(CLEAR_VARS)

 LOCAL_PATH := $(MY_PATH)

 LOCAL_LDLIBS := -llog -ldl
 LOCAL_MODULE    := rmsdk
 LOCAL_SRC_FILES := native.c

 include $(BUILD_SHARED_LIBRARY)

它看起来不对劲。我想你可以试试这个:

 include $(call all-subdir-makefiles)

 include $(CLEAR_VARS)

 LOCAL_PATH := $(call my-dir)

 LOCAL_LDLIBS := -llog -ldl
 LOCAL_MODULE    := rmsdk
 LOCAL_SRC_FILES := native.c

 include $(BUILD_SHARED_LIBRARY)

希望它有帮助。


推荐