Tue Jun 4 16:50:19 CEST 1996

Hello, everybody!

A known bug in GPC is that it does not automatically read Unit
(or Module) interfaces when a Unit is used (or a Module is imported).
For that reason, something like

  gpc -c myunit.pas
  gpc myprog.pas myunit.o -o myprog

does only work when the main program (myprog.pas) (*$includes *) or
#includes the Module interface.  This is bearable with Extended Pascal
where you can have the interface in a separate file; with Borland style
Units you include the whole Unit, so it is recompiled each time.

However, there is a workaround which is just another bug in GPC:-)
A Borland style Unit with an empty implementation part but declaring
some procedures in the interface part is not rejected by the compiler,
only by the linker.  Therefore, we can use the following trick:

    ---- file: myprog.pas ----

    (*$I MyUnit *)  (* Include the *whole* file MyUnit.pas *)

    Program MyProg;



    ---- file: myunit.pas ----

    Unit MyUnit;


    Procedure Hello;


    (*$ifdef IMPLEMENTATION *)
    (* suppress re-compilation of implementation part *)

    Procedure Hello;
    begin (* Hello *)
      writeln ( 'Hello!' );
    end (* Hello *);

    (*$endif *)


Now you can compile the Unit separately with

    gpc -D IMPLEMENTATION -c myunit.pas

and then link it when compiling the main program via

    gpc myprog.pas myunit.o -o myprog

Okay? Try it.

Good luck!


More information about the Gpc mailing list