Board index » delphi » Linking Pascal routines into C programs

Linking Pascal routines into C programs

I've got some legacy metaware pascal routines that I want to call MS Visual
C (required).   Changes to the method of invoking the routines would be OK,
but I want to avoid changing  any code internal to the routines.  These
routines written as pascal programs without bodies, and the original intent
was to call these routines from assembly.  A typical program containing
callable routines is shown below:

program prog;

    var ...        { I assumed these variables are local to this program}

    procedure X(..); external;
    procedure X(..);
    begin
        ....
    end;

    procedure Y(..); external;
    procedure Y(..);
    begin
        ....
    end;
. { Note the period here with no program begin/end}

I assume that this is metaware's version of a unit at the time the code was
written.  Later metaware came out with Ada-like packages.   Here are my
questions.

1) Is there an existing compiler that can handle this style of code as is?
Metaware no longer offers pascal support.

2) If I did change the program to a unit or equivalent structure (or even if
it could be compiled as is), how would I call it from Visual C.  I have been
able to create C obj files in GCC and successfully link them into Visual C.

Thanks in advance,

Jim.

 

Re:Linking Pascal routines into C programs


Quote
In article <94dq9e$i6...@slb6.atl.mindspring.net>, James Whitmire wrote:
>I've got some legacy metaware pascal routines that I want to call MS Visual
>C (required).  

Then I think your only option is Delphi.. Other compilers might compile the
code, but probably won't be able to link to VC.

Re:Linking Pascal routines into C programs


We've got Delphi 5.0 at work.  It produces its own proprietary (I believe)
object format.  With a -J option, the Delphi compiler additionally produces
OMF formatted objects.  The Visual C++ linker doesn't accept Delphi
generatate OMF, but attemts to run a conversion routine (editbin or 1 other)
to transform these OMFs to COFF format (It fails).  I don't know what flavor
of OMF the Delphi compiler generates, but I have not been able to find a way
to convert Borland OMF to COFF.  I've been told that it is not possible, so
Delphi is a dead end unless I hear something different.

The GCC & GPC compiler both generate COFF.  I've compiled some simple C
routines under GNU, and then linked/run these objects under Visual C++, so I
know there is not an object file format problem.

I believe the problem for now how do I invoke these routines from the C
side, and in what way does the pascal code have to be altered to do this.
Does pascal have any separate compilation similar to a standalone C function
or any other way I can get my foot in the door on this problem.

Jim.

"Marco van de Voort" <mar...@toad.stack.nl> wrote in message
news:slrn96lff6.1d1e.marcov@toad.stack.nl...

Quote
> In article <94dq9e$i6...@slb6.atl.mindspring.net>, James Whitmire wrote:
> >I've got some legacy metaware pascal routines that I want to call MS
Visual
> >C (required).

> Then I think your only option is Delphi.. Other compilers might compile
the
> code, but probably won't be able to link to VC.

Re:Linking Pascal routines into C programs


Quote
In article <94ev9f$k5...@slb1.atl.mindspring.net>, James Whitmire wrote:
>We've got Delphi 5.0 at work.  It produces its own proprietary (I believe)

>The GCC & GPC compiler both generate COFF.  I've compiled some simple C
>routines under GNU, and then linked/run these objects under Visual C++, so I
>know there is not an object file format problem.

So does FPC iirc. But you can't link directly against C++ there.

Quote
>I believe the problem for now how do I invoke these routines from the C
>side, and in what way does the pascal code have to be altered to do this.
>Does pascal have any separate compilation similar to a standalone C function
>or any other way I can get my foot in the door on this problem.

Sorry, I don't know GPC internally.

Other Threads