I want to include a static library built for the C++ code provided, I tried linking the static library, but build cannot link the library. I am getting the following error:
undefined reference to 'Test_C_Interface'
I am new to Java NDK/cmake. Please help me with this
This is the cpp code used(native-lib.cpp)
extern int Test_C_Interface();
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_tvgui_MainActivity_stringFromJNI(JNIEnv *env, jobject /* this */) {
std::string hello = "From C++";
int ret_val;
ret_val = Test_C_Interface();
if(ret_val == 100){
hello = "From C";
}
return env->NewStringUTF(hello.c_str());
}
This is the c code used to make the static library(sample.c/libsample.a)[Library built using NDK ARM-v7a ToolChain]
#include<stdio.h>
int Test_C_Interface(void)
{
printf("Inside C Library\n");
return 100;
}
This is the cmake file
cmake_minimum_required(VERSION 3.4.1)
add_library(
native-lib
SHARED
native-lib.cpp)
find_library(
log-lib
log)
target_link_libraries(
native-lib
${log-lib}
${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/libsample.a)
I need to build a application from like :
libsample.a
\
\
====libnative-lib.so + Java = .apk
/
/
native-lib.cpp
UPDATE The problem was solved by modifying the code as below :
extern "C"{
int Test_C_Interface();
}