How to link any library in ndk application

Solution 1:

when you get "make: * No rule to make target `something.c'", it just means it can't find the file.

I'm a bit confused why you've organized your project like that, but if I was going to build your project, I would do it as follows:

(doesn't matter which directory)
|
-->(ndk_demo)
-->-->(jni)
-->-->-->Application.mk
-->-->-->Android.mk
-->-->-->com_marakana_NativeLib.h
-->-->-->ndk_demo.c
-->-->(stackoverflow)
-->-->-->stackoverflow.h
-->-->-->libstackoverflow.a

Then I would use the following makefile:

Android.mk:

LOCAL_PATH := $(call my-dir)

### include stackoverflow as a prebuilt lib ###

include $(CLEAR_VARS)

LOCAL_MODULE            := stackoverflow-prebuilt
LOCAL_SRC_FILES         := ../stackoverflow/libstackoverflow.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../stackoverflow

include $(PREBUILT_STATIC_LIBRARY)

### build your ndk lib ###

include $(CLEAR_VARS)

LOCAL_MODULE := ndk_demo
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
                    $(LOCAL_PATH)/../stackoverflow
LOCAL_SRC_FILES := ndk_demo.c

LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := stackoverflow-prebuilt

include $(BUILD_SHARED_LIBRARY)

And the following:

Application.mk:

APP_MODULES := ndk_demo
APP_PLATFORM := android-8

Then finally, I would navigate to the directory (ndk_demo) and run ndk-build.

ndk-build is android's build tool. You should use it. It can be found at:

(AndroidSDK)/(NDK)/ndk-build

if you are using windows, you will either have to type the full path of ndk-build into the console, or add an environment variable to your system before trying to run it.

http://www.windows7hacker.com/index.php/2010/05/how-to-addedit-environment-variables-in-windows-7/