Run Cross compiled C app that uses shared library for android device -
i couldn't find working example following:
i created shared library composed code below:
foo.c: #include
#include "foo.h" void foo(void) { printf("hello, i'm shared library\n"); }
and foo.h interface:
#ifndef __foo_h__ #define __foo_h__ void foo(void); #endif
the "foo" code reside under subdirectory foo
compiled using (i'll drop elaborated make options sake of simplicity):
#cross_compile is: #/usr/local/toolchain/arm-2010q1/bin/arm-none-linux-gnueabi- cc := $(cross_compile)gcc $(cc) -fpic -c foo.c -o foo.o $(cc) -shared -o libfoo.so foo.o
when building it- libfoo.so created successfully.
main.c file:
#include <stdio.h> #include "foo.h" int main(void) { printf("hello world\n"); foo(); return 0; }
and build app using:
$(cc) -c main.c -o main.o $(cc) main.o -lfoo -lfoo -o test
so far- ok executable , pushed /data/local/tmp/.
now, tried below without success (got error: test: no such file or directory)
- adb push libfoo.so /system/lib or /system/lib64
- copy /data/local/tmp/ , set ld_library_path accordingly
anyone has suggestion?
after digging little bit have found better approach use ndk rather standard makefile purpose.
a comprehensive tutorial helped me achieve want can found @ http://web.guohuiwang.com/technical-notes/androidndk1.
good luck
Comments
Post a Comment