[fpc-pascal] Linker error on simple program (windows)

Bart bartjunk64 at gmail.com
Wed Jun 23 15:20:43 CEST 2021


Given this unit:

unit ExtMath;

{$mode objfpc}

interface

function LeadingZeroBits(n: Byte): Integer; inline;

implementation

function LeadingZeroBits(n: QWORD; BitSize: Integer): Integer;
begin
  Result := 0;
end;


function LeadingZeroBits(n: Byte): Integer;
begin
  Result := LeadingZeroBits(QWORD(n), SizeOf(Byte)*8);
end;
end.

and this program

program test;
{$mode ObjFPC}

uses
  Extmath;

var
  b: byte;
  L: Integer;
begin
  b := 0;
  L := LeadingZeroBits(b);
end.

On Windows this won't build with 3.2.2 or 3.2.0.
It will build with 3.0.4.

C:\Users\Bart\LazarusProjecten\bugs\Console\linkerror>fpc test.pas
Free Pascal Compiler version 3.2.2 [2021/05/15] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
Compiling extmath.pp
test.pas(9,3) Note: Local variable "L" is assigned but never used
Linking test.exe
test.pas(13,1) Error: Undefined symbol:
EXTMATH_::=::\_LEADINGZEROBITS$QWORD$LONGINT::=::\LONGINT
test.pas(13,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\devel\fpc\3.2.2\bin\i386-win32\ppc386.exe returned an error exitcode

The error goes away if I remove the inline directive from the function
definition in the interface section, or if I also declare the other
function (which gives the linker error) in the interface section.

-- 
Bart


More information about the fpc-pascal mailing list