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

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

asked Mar 15 at 19:18

Vinh%20Le's gravatar image

Vinh Le
153

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..
link

answered Mar 15 at 20:50

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

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

By RSS:

Answers

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

Tags:

×98
×65
×45

Asked: Mar 15 at 19:18

Seen: 443 times

Last updated: Mar 15 at 23:16

powered by OSQA