[fpc-devel] Exporting functions in an Android library

Sergio Flores relfos at gmail.com
Tue Aug 19 06:43:27 CEST 2014


Hi again!
This mail is the continuation of the Androids threads problem.
As you guys said, the threads problem seems to be caused by using a old
version of the compiler, so I went and compiled fpc from trunk, for Android
target.
Then I tried compiling my game using the cross compiler I just built.

I had to make some changes to the compilation options:
Replaced -Tlinux with -Tandroid
Replaced -CfVFPV2 with -CfVFPV3
Removed -mfloat-abi=hard
Added new unit path (units\rtl-objpas, seems it was necessary for dateutils
now)

And then it compiled fine, generated a .so, like before. All seems ok, so I
compile my java code, and make an apk. When I try running the game now it
crashes at startup.

D/dalvikvm( 5667): Trying to load lib
/data/data/com.terra.minimon3d/lib/libterraARMV7.so 0x424967b8
E/AndroidRuntime( 5667): java.lang.UnsatisfiedLinkError: Cannot load
library: reloc_library[1307]:   111 cannot locate 'PASCALMAIN'...

Strange... So I run nm on the .so file to check exported symbols.
D:\code\minimonhd\trunk\Android\libs\armeabi-v7a>nm -g libterraARMV7.so
         U FPC_THREADVARTABLES
         U INITFINAL
         U PASCALMAIN
(and others, calloc, malloc, FPC_RESOURCESTRINGTABLES, etc)

Where are my own exported JNI functions, they are gone?
I had like 30 of them, that were correctly exported with an older FPC.

Confused by this, I compile the game again, but this time with the older
FPC version.
I then run nm on the .so and the functions are all there...
0005aa08 T JNI_OnLoad
0005aa34 T JNI_OnUnload
00059b30 T Java_com_pascal_terra_TERRALibrary_ApplicationContextLost
00059b2c T Java_com_pascal_terra_TERRALibrary_ApplicationGetOrientation
Etc...
Something curious, PASCALMAIN is not anywhere in the export symbols now.
And I don't even understand why this is being called when I load the
library in the Java side?

My own exported functions are all declared in the main file.
They are defined like this:

Procedure Java_com_pascal_terra_TERRALibrary_ApplicationShutdown(env,
obj:Pointer);  stdcall; export; [public];
Begin
...
End;

Note that even in the old compiler, if the functions are defined outside
the main file they were not exported, compiler bug or some kind of
limitation?
Also the part "export; [public];" seems necessary in Android, otherwise
they were also not exported correctly. I don't really understand what
[public] means, and sadly could not find documentation about it.
Finally, in the end of the main file I have an exports section, listing all
functions I want to export, all worked before so what changed that causes
the symbols to not be exported in the .so?

And why is this PASCALMAIN being exported, since I'm compiling a library
not a program?

Here's the complete compilation options I'm using, just in case I'm missing
something
-TAndroid -a -Parm -CpARMV7 -CfVFPV3 -gl -vewnhi -Xd -Sg -O-
-XParm-linux-androideabi-   -FUbuild -FEandroid\libs\%TARGET_OUTPUT%\
-olibterra%TARGET%.so
(plus fpc\units\rtl, rtl-objpas and 10 other paths belonging to my own
units)

Regards,
Sérgio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140819/cb186e47/attachment.html>


More information about the fpc-devel mailing list