Question:
I'm using Android Studio 1.5 with Android NDK to build but I can't link to static library. My folder stuct look like this: src --main
----jni
------chilkat
--------include
--------libs
------Android.mk
------Application.mk
------com_example_vinhle_ndksample2_MyNDK.h
------MyLibrary.cpp
Here is content of Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ChilkatAndroid
LOCAL_SRC_FILES := D:\Tutorials\Android\NDKSample2\app\src\main\jni\chilkat\libs\$(TARGET_ARCH_ABI)\libchilkatAndroid.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := ChilkatAndroid
LOCAL_C_INCLUDES = D:\Tutorials\Android\NDKSample2\app\src\main\jni\chilkat\include
LOCAL_MODULE := MyLibrary
LOCAL_SRC_FILES := MyLibrary.cpp
include $(BUILD_SHARED_LIBRARY)
And content of MyLibrary.cpp
#include "com_example_vinhle_ndksample2_MyNDK.h"
#include <stdio.h>
#include <C_CkRsa.h>
JNIEXPORT jstring JNICALL Java_com_example_vinhle_ndksample2_MyNDK_getMyString (JNIEnv *env, jobject){
HCkRsa rsa;
rsa = CkRsa_Create();
return (*env).NewStringUTF("So sad");
}
And this is error message appear when build with ndk-build.cmd
jni/MyLibrary.cpp:54: error: undefined reference to 'CkRsa_Create()'
collect2.exe: error: ld returned 1 exit status
make: *** [obj/local/x86_64/libMyLibrary.so] Error 1
Process finished with exit code 2
I think there is some problem with static library that was provided by chilkat android c/c++ because when I did like above with a static library that was built by me, the work is done with no error
You're trying to use the "C" API in C++.
Do this:
extern "C" { #include <c_ckrsa.h> }