[fpc-pascal] FPC linker oddity

patspiper patspiper at gmail.com
Sun Jun 21 21:43:58 CEST 2015


The following simple program which uses the $LINKLIB compiler directive 
builds fine under Linux:

program Project1;
{$Linklib c}
Const P : PChar = 'This is fun !';
Function strlen (P: PChar): Longint; cdecl; external;
begin
   WriteLn ('Length of (',p,') : ',strlen(p))
end.

However, cross-compiling to Windows a similar program fails:
program Project1;
{$Linklib kernel32}
   Function GetTickCount: DWORD; external;
begin
   WriteLn ('GetTickCount ', GetTickCount);
end.
project1.lpr(10,1) Error: Undefined symbol: 
P$PROJECT1_$$_GETTICKCOUNT$$LONGWORD

Changing the GetTickCount declaration to any of the following works:
   Function GetTickCount: DWORD; external name 
'_$dll$kernel32$GetTickCount';
   Function GetTickCount: DWORD; external 'kernel32';

Why is the behaviour different between Linux and Windows?

Stephano



More information about the fpc-pascal mailing list