View Issue Details

IDProjectCategoryView StatusLast Update
0018596FPCCompilerpublic2011-01-28 13:43
ReporterJan Bruns Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformX64OSLinux 
Product Version2.4.0 
Summary0018596: Linking a dynlib fails, depending on used units
Descriptionfpc fails to link dynlibs, that use units, which implement global vars.

The dynlib itself can make use of global vars.
Steps To Reproduce////////////////////
unit unit1; // fails

interface

var unitval : longint;

implementation

begin
  unitval := 123;
end.


////////////////////
unit unit2; // fails

interface

function unitval : longint;

implementation

var vunitval : longint;

function unitval : longint;
begin
  unitval := vunitval;
end;

begin
  vunitval := 123;
end.

////////////////////
unit unit3; // works

interface

function unitval : longint;

implementation

function unitval : longint;
begin
  unitval := 123;
end;

begin
end.

////////////////////
{$mode objfpc}
library linktest;
uses unit3;

var
addv : longint;

procedure setav;
begin
 addv := 2;
end;

procedure doit;
begin
  setav;
  writeln('Used unit says: ',unitval*addv );
end;

exports doit;
end.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

2011-01-24 04:16

 

linktest.pas (215 bytes)   
{$mode objfpc}

library linktest;
uses unit2;

var
addv : longint;

procedure setav;
begin
 addv := 2;
end;


procedure doit;
begin
  setav;
  writeln('Used unit says: ',unitval*addv );
end;


exports doit;

end.


linktest.pas (215 bytes)   

2011-01-24 04:17

 

unit1.pas (97 bytes)   

unit unit1;

interface

var unitval : longint;

implementation



begin
  unitval := 123;
end.
unit1.pas (97 bytes)   

2011-01-24 04:17

 

unit2.pas (190 bytes)   

unit unit2;

interface

function unitval : longint;


implementation

var vunitval : longint;

function unitval : longint;
begin
  unitval := vunitval;
end;

begin
  vunitval := 123;
end.
unit2.pas (190 bytes)   

2011-01-24 04:17

 

unit3.pas (144 bytes)   

unit unit3;

interface

function unitval : longint;


implementation



function unitval : longint;
begin
  unitval := 123;
end;

begin
 end.
unit3.pas (144 bytes)   

Jan Bruns

2011-01-27 04:30

reporter   ~0045503

Ah. Rebuiling using "-fPIC" helps. Fpc also gives a note about this in the error message. Of course I tried that many times before opening this bug-report, but maybe I always forgot to rebuild everything:

fpc -B -fPIC linktest

Jonas Maebe

2011-01-28 13:43

manager   ~0045534

Thanks for the follow-up.

Issue History

Date Modified Username Field Change
2011-01-24 04:15 Jan Bruns New Issue
2011-01-24 04:16 Jan Bruns File Added: linktest.pas
2011-01-24 04:17 Jan Bruns File Added: unit1.pas
2011-01-24 04:17 Jan Bruns File Added: unit2.pas
2011-01-24 04:17 Jan Bruns File Added: unit3.pas
2011-01-27 04:30 Jan Bruns Note Added: 0045503
2011-01-28 13:43 Jonas Maebe Status new => resolved
2011-01-28 13:43 Jonas Maebe Resolution open => no change required
2011-01-28 13:43 Jonas Maebe Assigned To => Jonas Maebe
2011-01-28 13:43 Jonas Maebe Note Added: 0045534