login about faq

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 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 $(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/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

asked Mar 15 at 19:18

Vinh%20Le's gravatar image

Vinh Le

edited Mar 15 at 19:20

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

Do this:

extern "C" {
#include <c_ckrsa.h>
  • Make sure to familiarize yourself with C++ name mangling and how to use "C" functions / headers in C++.
  • Why are you using the "C" API when Chilkat also provides a C++ API with classes? If you're source is C++, it would seem more natural to use the Chilkat C++ classes..

answered Mar 15 at 20:50

chilkat's gravatar image

chilkat ♦♦

Thank you! My problem was solved! I'm coding in C#/Windows Phone/Universal, so when I met this issue when joined the project with C/C++

(Mar 15 at 23:16) Vinh Le
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Mar 15 at 19:18

Seen: 359 times

Last updated: Mar 15 at 23:16

powered by OSQA