Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-04

android share library with classes unit

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

herux

I managed to compile and run the library for android on emulator, which I compile the project just a libhellojni.so

compile using paramater like this

ppcarm -Scghi -O1 -Parm -gl -b -B -XX -Xc -XD -CpARMv6 -CfSOFT -dandroid -vewnhi -l -XParm-linux-
-Fi/home/herux/workspace/hellojni/jni/lib/arm-linux/ -Fu. -FUlib/arm-linux/ -o../libs/armeabi/libhellojni.so -FD/usr/share/fpcsrc/binutils/ hellojni.lpr

on Kubuntu 10.04 x86_64

library code:

library hellojni;
{$ ifdef fpc}
  {$ mode delphi}
{$ endif}
uses
     JNI, log;
Java_com_herux_hellojni_MainActivity_Hellojni function (env: PJNIEnv; Thiz:
jobject): jstring; cdecl;
begin
   result: = env ^. NewStringUTF (env, PChar ('Hello JNI from FreePascal
..'));
end;
exports
        Java_com_herux_hellojni_MainActivity_Hellojni name
'Java_com_herux_hellojni_MainActivity_Hellojni';
begin
end;

then I try to use classes unit or sysutils, the project succeeded in compiling, but the library did not loaded by the emulator. there is an error SIGSEGV

D/dalvikvm( 1082): Trying to load lib
/data/data/com.herux.hellojni/lib/libhellojni.so 0x44e7ea48 I/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 31): Build fingerprint:
'generic/sdk/generic/:2.2/FRF91/43546:eng/test-keys' I/DEBUG ( 31): pid: 1082, tid: 1082 >>> com.herux.hellojni <<< I/DEBUG ( 31): signal 11 (SIGSEGV), fault addr 7eb67b08 I/DEBUG ( 31): r0 7eb67b08 r1 7eb67b08 r2 00000000 r3 0000003d I/DEBUG ( 31): r4 00000006 r5 809aa4cc r6 b001037c r7 00000000 I/DEBUG ( 31): r8 80813b00 r9 0000ccb0 10 4186b904 fp beb1986c I/DEBUG ( 31): ip beb19870 sp beb19818 lr 809ab5d4 pc 809ab56c cpsr 60000010
I/DEBUG ( 31): #00 pc 000ab56c
/data/data/com.herux.hellojni/lib/libhellojni.so
I/DEBUG ( 31): #01 lr 809ab5d4
/data/data/com.herux.hellojni/lib/libhellojni.so
I/DEBUG ( 31):
I/DEBUG ( 31): code around pc:

if anyone has ever experienced it? or is it a bug?

thanks

-----
-

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/android-share-library-with-classes-unit-tp4297859p4297859.html Sent from the Free Pascal - General mailing list .
Dariusz Mazur
to herux

W dniu 2011-04-12 11:56, herux pisze:

Show quoted text 19 lines
I managed to compile and run the library for android on emulator, which I compile the project just a libhellojni.so compile using paramater like this ppcarm -Scghi -O1 -Parm -gl -b -B -XX -Xc -XD -CpARMv6 -CfSOFT -dandroid -vewnhi -l -XParm-linux- -Fi/home/herux/workspace/hellojni/jni/lib/arm-linux/ -Fu. -FUlib/arm-linux/ -o../libs/armeabi/libhellojni.so -FD/usr/share/fpcsrc/binutils/ hellojni.lpr on Kubuntu 10.04 x86_64 library code: library hellojni; {$ ifdef fpc} {$ mode delphi} {$ endif} uses JNI, log; Java_com_herux_hellojni_MainActivity_Hellojni function (env: PJNIEnv; Thiz: jobject): jstring; cdecl; begin result: = env ^. NewStringUTF (env, PChar ('Hello JNI from FreePascal ..')); end; exports Java_com_herux_hellojni_MainActivity_Hellojni name 'Java_com_herux_hellojni_MainActivity_Hellojni'; begin end; then I try to use classes unit or sysutils, the project succeeded in compiling, but the library did not loaded by the emulator. there is an error SIGSEGV D/dalvikvm( 1082): Trying to load lib /data/data/com.herux.hellojni/lib/libhellojni.so 0x44e7ea48 I/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** I/DEBUG ( 31):

How You prepare crosscompiler
did You use -dARMEL -CpARMv6

or problems with binutils

On Android each bug in linking is showing the same

Darek

herux
to Dariusz Mazur

I use this binutils http://www.gnu.org/software/binutils/ using this command to build crosscompiler

make clean crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/usr/share/fpcsrc/binutils/ OPT="-dFPC_ARMEL -O- -gl" CROSSOPT="-dANDROID -CpARMv6 -gl -CfSOFT -O-"

I may have to repeat it

thank u

-----
-

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/android-share-library-with-classes-unit-tp4297859p4299510.html Sent from the Free Pascal - General mailing list .
Unknown author
to herux: I use this binutils http://www.gnu.org/software/binutils/ using this command to build…
Show quoted text 6 lines
I use this binutils http://www.gnu.org/software/binutils/ using this command to build crosscompiler make clean crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=/usr/share/fpcsrc/binutils/ OPT="-dFPC_ARMEL -O- -gl" CROSSOPT="-dANDROID -CpARMv6 -gl -CfSOFT -O-"

CROSSOPT="-dANDROID -CpARMv6 -dFPC_ARMEL "

I've trace Your debug log. Bug is on line where library is loaded. It seems be corrupted. I always had once more line with absent of dlopen

D/dalvikvm( 1082): Trying to load lib
/data/data/com.herux.hellojni/lib/libhellojni.so 0x44e7ea48

here something with "dlopen", I don't remember exactly. ^^^^^^^^^^^
I/DEBUG ( 31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

Darek

Thomas Schatzl
to herux: I managed to compile and run the library for android on emulator, which I compile the…

Hi,

herux wrote 20 lines
I managed to compile and run the library for android on emulator, which I compile the project just a libhellojni.so compile using paramater like this ppcarm -Scghi -O1 -Parm -gl -b -B -XX -Xc -XD -CpARMv6 -CfSOFT -dandroid -vewnhi -l -XParm-linux- -Fi/home/herux/workspace/hellojni/jni/lib/arm-linux/ -Fu. -FUlib/arm-linux/ -o../libs/armeabi/libhellojni.so -FD/usr/share/fpcsrc/binutils/ hellojni.lpr [...] then I try to use classes unit or sysutils, the project succeeded in compiling, but the library did not loaded by the emulator. there is an error SIGSEGV

Fyi, there is an unresolved issue with Android shared library initialization code which affects the use of the sysutils unit, see http://bugs.freepascal.org/view.php?id=18833 for more details.

Thomas

herux
to Thomas Schatzl

My problem is resolved, I apply the patch contained in that link. reported by Dejan Boras.
then rebuild cross compiler with this:

make clean crossinstall CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR="/usr/share/fpcsrc/binutils" OPT="-dFPC_ARMEL -O- -gl" CROSSOPT="-dANDROID -CpARMv5 -gl -CfSOFT -O-"

now it's work. libhellojni.so loaded succesfully.

thanks

herux

-----
-

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/android-share-library-with-classes-unit-tp4297859p4300489.html Sent from the Free Pascal - General mailing list .
Felipe Monteiro de Carvalho
to herux

Forwarding to the mailling list:

heru susanto wrote 27 lines
I've done the second step here : #!/bin/sh /usr/local/bin/arm-linux-as_org -march=armv6 -meabi=5 -mfloat-abi=softfp -mfpu=vfp3 $@ my problem have been solved. my next problem is dynamic linking. thank you herux On Wed, Apr 13, 2011 at 3:29 PM, Felipe Monteiro de Carvalho wrote: > > Have you done "Step 2" described here: > > > http://wiki.lazarus.freepascal.org/Android_Interface#Using_the_pre-compiled_compiler > > ? > > I know that those instructions are different from what you are doing, > but Step 2 should apply anyway. > > -- > Felipe Monteiro de Carvalho