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

Oliver Graf ograf at oli-ver-ena.de
Mon Jun 18 13:50:58 CEST 2001


Hi myself!

On Mon, Jun 18, 2001 at 12:43:50PM +0200, Oliver Graf wrote:
> 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.
> 
> Has anyone done this before and can provide us with some hints how
> to archive this (i.e. creating a C header for the unit, calling
> conventions, argument passing)?
> 
> Target system is linux.

This now breaks down to: which fpc runtime libs do I need to link
(basically) to a C programm which uses a pascal unit? I've added
rtl/libsyslinux.a and rtl/libsysutils.a, but _haltproc and INITFINAL
(used in libsyslinux.a) are still missing.

example:

compile unit with 'fpc test'

try to compile C with 'gcc test.c test.o /usr/lib/fpc/1.0.4/units/linux/rtl/libsysutils.a /usr/lib/fpc/1.0.4/units/linux/rtl/libsyslinux.a -o doittest'

Any hints?

Oliver.

-+-+-+ test.pas
unit test;

interface

procedure doit(i : integer); cdecl;

implementation

procedure doit(i : integer); cdecl; export;

begin
   writeln('Hello World!');
   writeln(i);
   writeln();
end; { doit }

end.
-+-+-+

-+-+-+ test.h
void doit(int i);
-+-+-+

-+-+-+ test.c
#include <stdio.h>

#include "test.h"

int main(int argc, char **argv) {
  doit(1);
  return 0;
}
-+-+-+





More information about the fpc-pascal mailing list