[fpc-pascal]External variables in FPC

md md at realmwireless.com
Thu Nov 23 18:15:36 CET 2000


This is an update for all FPC developers using FPC under Linux.

If you ever need to create FPC coded shared library  (XXX.SO) make use
of variables which are also used by either a pascal or C application
using the shared library,  make sure you provide a function to pass
pointers to storage allocation to the library so that the library uses
pointers to the variables while the application can access them
directly.

Avoid "EXTERNAL" and "CVAR" like the plague.

The {$MODE} compiler switch causes all sorts of headaches when trying to
create a shared library with exported
variables in the shared library. Delphi mode does not allow for it, only
FPC mode.  But most of the code is
in delphi mode anyway.

Finally, when you get to the point of trying to use the shared library
from both pascal and C, you will never get the compilation just right to
satisfy all the type sizes and so forth.

You could of course create the shared library in C and all the above
problems go away, but this is for libraries compiled under FPC.

So again, use pointers to variables inside the shared library, provide a
function to initialize those pointers to the addresses of variables
inside the application.  Happy FPCing.

Mark Diener
md at realmwireless.com.




More information about the fpc-pascal mailing list