没有制定目标 NDK 的规则

2022-01-10 00:00:00 android-ndk android java

我正在编译原生源代码并使用 .a 库和具有以下结构的相关头文件添加依赖项.

/jni/

<块引用>

Android.mk

LOCAL_PATH := $(call my-dir)包括 $(调用所有子目录生成文件)包括 $(CLEAR_VARS)LOCAL_LDLIBS := -llog本地模块:= ndk1LOCAL_SRC_FILES := native.cLOCAL_STATIC_LIBRARY := mschema包括 $(BUILD_SHARED_LIBRARY)

<块引用>

native.c

/jni/prereqs/

<块引用>

Android.mk

LOCAL_PATH := $(call my-dir)包括 $(调用所有子目录生成文件)包括 $(CLEAR_VARS)

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

/jni/prereqs/mschema/

<块引用>

Android.mk

LOCAL_PATH := $(call my-dir)包括 $(CLEAR_VARS)LOCAL_MODULE :=mschemaLOCAL_SRC_FILES :=libmschema.aLOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include包括 $(PREBUILT_STATIC_LIBRARY)

<块引用>

libmschema.a

/jni/prereqs/mschema/include

<块引用>

头文件.(.h)

但在尝试 ndk-build (NDK5) 时出现以下错误.

marcos@marcos-AY675AA-AC4-s5320br:~/dev/workspace/rmsdk.native.wraper$ ndk-buildmake:*** 没有规则来制作目标 `/home/marcos/dev/workspace/rmsdk.native.wraper/jni/prereqs/mschema/native.c',需要 `/home/marcos/dev/workspace/rmsdk.native.wraper/obj/local/armeabi/objs/ndk1/native.o'.停止.

在打字时我注意到错误是关于 /home/marcos/dev/workspace/rmsdk.native.wraper/jni/prereqs/mschema/native.c' 而实际上这个文件在/home/marcos/dev/workspace/rmsdk.native.wraper/jni/native.c',我的make文件有什么问题?

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

LOCAL_PATH := $(call my-dir)包括 $(调用所有子目录生成文件)LOCAL_PATH :=/home/marcos/dev/workspace/rmsdk.native.wraper/jni包括 $(CLEAR_VARS)LOCAL_LDLIBS := -llog本地模块:= ndk1LOCAL_SRC_FILES := native.cLOCAL_STATIC_LIBRARY := mschema包括 $(BUILD_SHARED_LIBRARY)

但它看起来不对.有更好的方法吗?

解决方案

从 NDK 5 的 Docs 中,解决方案是创建一个局部变量..

我的目录返回最后包含的 Makefile 的路径,通常是当前 Android.mk 的目录.这有助于定义LOCAL_PATH 在您的 Android.mk 开头,如下所示:

 LOCAL_PATH := $(call my-dir)重要提示:由于 GNU Make 的工作方式,这确实返回*last* *included* *Makefile* 在解析过程中的路径构建脚本.包含另一个文件后不要调用 my-dir.

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

 LOCAL_PATH := $(call my-dir)MY_PATH := $(LOCAL_PATH)包括 $(调用所有子目录生成文件)包括 $(CLEAR_VARS)LOCAL_PATH := $(MY_PATH)LOCAL_LDLIBS := -llog -ldlLOCAL_MODULE := rmsdkLOCAL_SRC_FILES := native.c包括 $(BUILD_SHARED_LIBRARY)

及其作品.

I'm compiling native sources and adding the dependencies with .a libs and those relative header files with the following structure.

/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)

--Used to call the sub-folders mk files

/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

Header files. (.h)

But while trying to ndk-build (NDK5) I got the following error.

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.

While typing I noted the error is about /home/marcos/dev/workspace/rmsdk.native.wraper/jni/prereqs/mschema/native.c' and actually this file is under/home/marcos/dev/workspace/rmsdk.native.wraper/jni/native.c', what's wrong in my make files?

The problem could be avoided by changing the first Android.mk to the following:

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)

But it looks wrong. Is there a better approach?

解决方案

From the Docs in NDK 5, the solution is to create a local variable..

my-dir Returns the path of the last included Makefile, which typically is the current Android.mk's directory. This is useful to define LOCAL_PATH at the start of your Android.mk as with:

    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.

So.. to solve this problem I change my Android.mk to the following.

 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)

And its works.

相关文章