how to compile static linked application using android cross compilation toolchain?

1,117 views
Skip to first unread message

Anatoly Korniltsev

unread,
Jan 10, 2012, 8:09:48 PM1/10/12
to android-ndk
I am trying to compile fbgrab fbgrab website for arm devices.

I managed to build it using this command

arm-linux-androideabi-gcc --sysroot=$NDK_ROOT/platforms/android-8/arch-
arm/ -lz -lm -I../zlib -I../lpng -W -Wall -o fbgrab fbgrab.c ../
zlib/libz.a ../lpng/libpng.a
but it is dynamicly linked and i dont now how to install shared
libraries on device

localhost:fbgrab-1.0 anatoly$ file fbgrab
fbgrab: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically
linked (uses shared libs), not stripped
So i need to build it with static linked libraries when i try to use -
static option compilation fails with this message ld: cannot find -lz
although shared libraries are located in pointed directories

what is the problem here? how to build static linked binary? or how am
i able to install shared libraries on to device?

Chihwah Li

unread,
Jan 11, 2012, 7:05:04 AM1/11/12
to andro...@googlegroups.com

Hello,

Could this be of any help?

1) in the Android.mk file you mentioned which source to use.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c


2) In the java file you use the following code to include the static
library.
link : http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/

3) building under Linux: I use ndk-build under linux project folder to
create the shared library.


4) Then in Eclipse the android app is created by run


correct me if I am wrong.

Greetings,
cw

Op 11-1-2012 2:09, Anatoly Korniltsev schreef:

Anatoly Korniltsev

unread,
Jan 11, 2012, 9:05:09 AM1/11/12
to android-ndk
thanks for respond
i do not use ndk-build. i used it trying make a wraper around this app
but decided to build linux executable binary not library and call
directly from java code

Tor Lillqvist

unread,
Jan 11, 2012, 9:35:16 AM1/11/12
to andro...@googlegroups.com
> arm-linux-androideabi-gcc --sysroot=$NDK_ROOT/platforms/android-8/arch-arm/ -lz -lm -I../zlib -I../lpng -W -Wall -o fbgrab fbgrab.c ../zlib/libz.a ../lpng/libpng.a

Why do you specify both -lz and libz.a?


> but it is dynamicly linked

Have you checked which libraries it links to dynamically? (Using arm-linux-androideabi-readelf -d .) There are no static versions of the system libraries like libc as far as I know, you will always link to those dynamically.

As such, I am not sure if what you are doing, executing a "normal" executable file from your app's Java code, is supported and works for normal users on normal devices. ( (You presumably want to unpack and chmod that executable from your app's .apk in its startup code.)

> I dont now how to install shared libraries on device

Put them in libs/armeabi-v7a (or libs/armeabi, I think the other one is), and ant will include them in the .apk, and they will be unpacked into your application's /data/data/foo/.bar.zap/lib directory when the app is installed. You can then dlopen() them as long as you do it in the right order. Do not expect run-time linker to be able to do it automatically. (But for separate executables, it might actually work, as long as you set LD_LIBRARY_PATH for the process before execing the executable.)

In general, I would say you need to learn that Android is quite far from normal Linux, and stop trying to do things as you would on Linux...

--tml

Reply all
Reply to author
Forward
0 new messages