Archived Forum Post

Index of archived forum posts


How to build Android C/C++ version?

Mar 15 '16 at 23:16

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







Here is content of

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 $(CLEAR_VARS)
LOCAL_C_INCLUDES = D:\Tutorials\Android\NDKSample2\app\src\main\jni\chilkat\include
LOCAL_SRC_FILES := MyLibrary.cpp

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

Accepted Answer

You're trying to use the "C" API in C++.

Do this:

extern "C" {
#include <c_ckrsa.h>