Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No rule to make target NDK

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?

like image 605
Marcos Vasconcelos Avatar asked Jan 03 '11 15:01

Marcos Vasconcelos


1 Answers

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.

like image 51
Marcos Vasconcelos Avatar answered Oct 08 '22 14:10

Marcos Vasconcelos