interfacing g77 and free pascal

62 Views Asked by At

I have forced a free-pascal object to almost-work with a g77 main. The problem is that the g77 loader does not load a pascal library, so any attempt to insert writeln in the pascal code fails because FPC-IOCHECK, fpc_get_output .. are not found. Without I/O it works. Anyone knows a fix of the form -lPASCAL? There is a 30-year history that justifies this step; I understand perfectly that the request should seem foolish. thanks.

I work with UBUNTU 20.4

g77 -v says

Configured with: ../src/configure -v --enable-languages=c,c++,f77,pascal --prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --program-suffix=-3.4 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug x86_64-linux-gnu Thread model: posix gcc version 3.4.6 (Ubuntu 3.4.6-6ubuntu5)

There are three units:

main.f:

   10 WRITE (6,'(A,$)') '0 to stop>'
      READ (5,*) I
      IF (I.EQ.0) STOP
      CALL INFACE (I)
      GOTO 10
      STOP
      END
      SUBROUTINE PRINTER (I,R)
      INTEGER*4 I
      REAL*8 R
      WRITE (6,*) 'received',I,R
      RETURN
      END

inter.c

    include <stdio.h>
    extern void SUB_$$_PROC1_$SMALLINT();
    extern void SUB_$$_PRINTNOW_$SMALLINT$REAL();
    extern void printer_();
    extern void printnow();
    extern void inface_(int*);
    void inface_(i)
    int *i; { int j; SUB_$$_PROC1_$SMALLINT(i); }
    void SUB_$$_PRINTNOW_$SMALLINT$REAL(i,r)
    int i; double r; {printf("route 3.0.4 "); printer_(&i,&r);}
    void printnow_(i,r)
    int i; double r; {printf("route 3.2.0 "); printer_(&i,&r);}

sub.p:

    unit sub;
    interface
    procedure PROC1_(var i:integer);
    procedure printnow_(i:integer; r:real); external;
    implementation 
    procedure PROC1_(var i:integer);
    var r:real;
    begin r:=2*sqrt(i); printnow_(i,r); {writeln('a');} end; 
    end.

I have compiled with

fpc -Un sub.p (either versions 3.0.4 and 3.2.0)

g77 main.f inter.c sub.o

All works with writeln commented, the link fails otherwise. Note that the C-routine called is different with fpc-3.0.4 and fpc-3.2.0.

0

There are 0 best solutions below