I've just started using GNU Pascal to port some legacy code across to Windows95/NT. I'm using DJGPP with the 19990118 beta copy of GPC.
Everything appears to be working fine until I get to the linking stage. I'm getting unresolved references to Pascal procedures declared externally.
I suspect I must be getting something fairly basic wrong, but I can't even get an example from the GPC documentation to build successfully!
Suggestions would be gratefully received.
Mike Ainsworth
Example: -- foobar.pas -- module foobar;
type footype = integer; var foo : footype;
procedure setfoo(f : footype); begin foo := f; end;
function getfoo : footype; begin getfoo := foo; end;
end.
-- what.pas -- program what(output);
type footype = integer;
procedure setfoo(f : footype); external; function getfoo : footype; external;
begin setfoo(999); writeln(getfoo); end.
-- Output -- gpc -o modtest.exe foobar.o what.o -lm -lgpc Error: what.o: In function `program_What': what.pas(8) Error: undefined reference to `Setfoo' what.pas(10) Error: undefined reference to `Getfoo'
========================================================================== Mike Ainsworth Praxis Critical Systems Limited, 20 Manvers Street, Bath BA1 1PX Tel: +44 1225 466991 Fax: +44 1225 469006 Email: ma@praxis-cs.co.uk ======= Software Engineering Safety-Critical Systems =======
From: Mike Ainsworth ma@praxis-cs.co.uk To: "'gpc@hut.fi'" gpc@hut.fi Subject: External references in GNU Pascal Date: Thu, 1 Apr 1999 11:50:23 +0100
I've just started using GNU Pascal to port some legacy code across to Windows95/NT. I'm using DJGPP with the 19990118 beta copy of GPC.
Everything appears to be working fine until I get to the linking stage. I'm getting unresolved references to Pascal procedures declared externally.
I suspect I must be getting something fairly basic wrong, but I can't even get an example from the GPC documentation to build successfully!
[...]
Well, I don't know much about Extended Pascal modules, but GPC does support Borland Pascal ("BP") "units".
Here is my conversion of your example (using a BP-style unit). Others will be able to give you examples using EP "modules".
With my example below, compile "what.pas" with this command line;
"gpc what.pas -o what.exe --automake"
Example;
-- foobar.pas -- unit foobar;
interface
type footype = integer; procedure setfoo(f : footype); function getfoo : footype;
implementation
var foo : footype;
procedure setfoo(f : footype); begin foo := f; end;
function getfoo : footype; begin getfoo := foo; end;
end.
-- what.pas -- program what(output);
uses foobar;
begin setfoo(999); writeln(getfoo); end.
BTW: if you are moving your code to the Windows platform, why not use the mingw32 version of GPC, instead of djgpp ?
Best regards, The Chief -------- Dr. Abimbola A. Olowofoyeku (The African Chief) Email: laa12@keele.ac.uk Homepage: http://ourworld.compuserve.com/homepages/African_Chief/ Author of: Chief's Installer Pro v5.00 for Win32 ftp://ftp.simtel.net/pub/simtelnet/win95/install/chief500.zip
Mike Ainsworth wrote:
I suspect I must be getting something fairly basic wrong, but I can't even get an example from the GPC documentation to build successfully!
The part of the documentation you are referring to is marked "outdated". What you tried to compile is a "somewhat simpler GPC-specific module" which was supported by older versions of GPC, is currently unsupported but might be reanimated as the PXSC-style module.
GPC supports ISO-10206 Extended-Pascal modules as well as UCSD Pascal units, which I prefer. (The latter ones are popular because they are also supported by Borland Pascal.)
Hope this helps,
Peter