[fpc-devel] Exporting functions in an Android library

Sven Barth pascaldragon at googlemail.com
Tue Aug 19 07:48:02 CEST 2014


On 19.08.2014 06:43, Sergio Flores wrote:
> 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)

Yes, the change to -Tandroid and the inclusion of rtl-objpas is 
expected. Afterall Android is now a fully supported target and the 
latter was because we've split up the RTL a bit.

> 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;

Better try to use an "exports" section in the mainfile instead of 
"export; [public];". See here (even related to Java) 
http://wiki.freepascal.org/Using_Pascal_Libraries_with_Java and here 
http://www.freepascal.org/docs-html/ref/refse100.html

Sidenote: the standard calling convention for Java is AFAIK "cdecl". It 
does not matter on ARM as there is all calling conventions are the same 
anyway, but on android-x86 that will matter...

> 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.

Then you didn't look good enough ;) 
http://www.freepascal.org/docs-html/ref/refsu77.html#x185-19500014.9.12

> 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?

Exporting functions without an "exports"-clause is a bit fragile. Could 
be that a bug was fixed or a bug was introduced. I don't know currently...

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

Even libraries have a main entrypoint. It's the "begin ... end." inside 
the library file and this one is also responsible for initializing all 
used units.

Regards,
Sven



More information about the fpc-devel mailing list