[fpc-pascal]linking pascal objects/units into C

Fernando Lozano fsl at centroin.com.br
Mon Jun 18 13:24:13 CEST 2001

Hi Oliver,

> We have a pretty old pascal project (delphi 1 on win95 -- already
> ported) and we need to interface it with various script languages
> (python, perl, etc.). So we need to link the pascal units to some
> C interfacing code for those script languages.

This is not hard at all, as FPC can use C calling conventions and can
gennerate standard linux dynamic libraries (*.so). You just have to be
carefull about different data types supported by each language, and how
to provide the "external" declarations for C and Pascal. Hint: never use
pascal Strings, use pchar and ansistrings. I guess integers and real are

Other hint: of your library use standard pascal procedures (like
writeln) you'll have to link the C programs against the pascal system
unit, and I don't know how to do that. But if you rewrite everything to
use Unix system calls (the unit linux) everything'll be fine. (please
anyone tell me if I am wrong).

I am sending a very simple sample where I build a dynamic library
(lteste.pas) and call it both from a pascal program (teste2.pas) and a C
program (teste3.pas). I'm sorry, the comments are on portuguese, but
they are so simple you'll understand anyway.

[]s, Fernando Lozano
-------------- next part --------------
#include <stdio.h>

extern int porcento (int p, int t);

int main (int argc, char* argv[])
    printf ("20%% de 50 vale: %d\n", porcento (20, 50));

-------------- next part --------------
A non-text attachment was scrubbed...
Name: teste2.pas
Type: application/x-unknown-content-type-pas_auto_file
Size: 155 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20010618/e69b1a3f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lteste.pas
Type: application/x-unknown-content-type-pas_auto_file
Size: 151 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20010618/e69b1a3f/attachment-0001.bin>

More information about the fpc-pascal mailing list