Calling Free Pascal Procedures from GnuCOBOL in Windows

I’m slowly working through various experiments with gnuCOBOL. One experiment is to call Pascal code from a gnuCOBOL program. The gnuCOBOL FAQ has an example, but I presume this only works for Linux. It definitely doesn’t work for MinGW/Windows.

I spent entirely too much time trying to get this experiment to work; thus, the blog post. I don’t want to forget how to do this.

The sample Pascal program (pascalCode.pas):

library pascalCode;
{$mode objfpc}{$H+}

procedure testp;
begin
writeln('Hello World!');
end;

procedure zippy;
begin
writeln('zippy');
end; // zippy

exports
    testp,
    zippy;

begin
end.

Here is the COBOL program(test.cbl):

       >>SOURCE FREE
identification division.
program-id.
    test.

procedure division.

0000-mainline.

    display "calling Pascal".
    call "testp",
        returning omitted.
    call "zippy",
        returning omitted.
    display "called Pascal".

0099-exit.

    stop run.

To compile and run:

export COB_PRE_LOAD=pascalCode
fpc pascalCode.pas
cobc -x test.cbl -L. -l:pascalCode.dll
./test

and the results:

./test
calling Pascal
Hello World!
zippy
called Pascal

 

This entry was posted in c-gnuCOBOL and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.