android - How to build an shared library and call it in other ndk program -


i want build shared library. build it, need call shared library. here did:

1.create 1 android project,named "buildlib",and add new folder "jni" under project directory. contents of jni folder:

jni-->android.mk
-->application.mk
-->add.cpp
-->add.h add.cpp 2 numbers addition:

add.h:

int add(int a,int b);

add.cpp:

#include "add.h"   int add(int a,int b){     return a+b;} 

android.mk:

local_path := $(call my-dir) include $(clear_vars) local_src_files  := add.cpp  local_module     := add include $(build_shared_library) 

after build project,i got libadd.so under directory $(buildlib)/libs/armeabi/.

create android project, named "calllib". copy libadd.so , add.h jni folder, create android.mk, application.mk, , call_add.cpp.

android.mk:

local_path := $(call my-dir) include $(clear_vars) local_src_files := libadd.so local_module := add_prebuilt include $(prebuild_shared_library)  include $(clear_vars) local_c_includes := $(local_path) local_src_files  := call_add.cpp  local_module     :=  native local_shared_libraries := add_prebuilt include $(build_shared_library) 

call_add.cpp:

#include "add.h" int call_add(){return add(1,2);} 

after above, build calllib project, got error:

undefined reference 'add(int, int)';

i think libadd.so can not found, don't know how modify. know how can fix this? appreciated.

in second android.mk, try replacing first module with:

local_path := $(call my-dir) include $(clear_vars) local_src_files := libadd.so local_module := add_prebuilt local_export_c_includes := add.h include $(prebuild_shared_library) 

the local_export_c_includes flag should attach header information add_prebuilt module, can linked final library.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -