I have created a header file "abc.h" with declaration
int abc();
Then, I created a .cpp file "abc.cpp" with definition
int abc()
{
return 0;
}
Now I created a static library libabc.a from above files.
I have then created a HelloWorld Android project. Then I created a jni folder in it with subfolders "header" and "src" in it. In header folder I have put abc.h and in src folder I have put "abc.cpp". Now I have created another file "xyz.cpp" in jni folder which wants to use abc() function. But when I run ndk-build command I get this error. jni/JNIMagicCleanManager.cpp:84: error: undefined reference to function abc (something like this)
How to get definition of abc() with the static library libabc.a I have put libabc.a in same folder parallel to Android.mk. Following is my Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MAGIC_CLEAN_ROOT := ..
MAGIC_CLEAN_SRC_ROOT := ../$(LOCAL_PATH)/src
MAGIC_CLEAN_SRC_FILES := xyz.cpp
MAGIC_CLEAN_C_INCLUDES := $(LOCAL_PATH)/headers/
LOCAL_STATIC_LIBRARIES := magicClean
LOCAL_MODULE := myJniLib2
LOCAL_SRC_FILES := $(MAGIC_CLEAN_SRC_FILES)
LOCAL_C_INCLUDES := $(MAGIC_CLEAN_C_INCLUDES)
LOCAL_C_INCLUDES += .
include $(BUILD_SHARED_LIBRARY)
Edit 1 : Many are asking why I have abc.cpp when I have static library, this is just for keeping code only. Please tell how to call the function from static library.