I am developing an android app where I have to use a shared library (cross-compiled on linux system using NDK toolchain).
Below are the steps I followed:
- I am using the 'hello-libs ndk sample'.
- The shared library name is
libsum.so
, where I have two function definitions:
int sum(int a, int b);
int sub(int a, int b);
- I have copied
libsum.so
file to the android app under path//hello-libs/app/libs/arm64-v8a
and calledsum(10, 20)
in//hello-libs/app/src/main/cpp/hello-libs.cpp
file. - Updated the
CMakeLists.txt
file to add shared library while compiling. UpdatedCMakeLists.txt
file below:
...
...
# configure import libs
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../distribution)
...
...
add_library(lib_sum SHARED IMPORTED)
set_target_properties(lib_sum PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/sum/lib/${ANDROID_ABI}/libsum.so)
# build application's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(hello-libs SHARED
hello-libs.cpp)
target_include_directories(hello-libs PRIVATE
${distribution_DIR}/gmath/include
${distribution_DIR}/gperf/include
${distribution_DIR}/sum/include)
target_link_libraries(hello-libs
android
lib_gmath
lib_gperf
lib_sum
log)
main.h
#include <stdio.h>
int sum(int a, int b);
int sub(int a, int b);
But I am getting the below error:
ld: error: undefined symbol: sum(int, int)
Can somebody please help me?