Dynamic Libraries dont work: win32 symbols arent exported, unix: exported vars dont share memory
Original Reporter info from Mantis: ivo_steinmann@gmx.net
-
Reporter name: Ivo Steinmann
Original Reporter info from Mantis: ivo_steinmann@gmx.net
- Reporter name: Ivo Steinmann
Description:
I have got 2 units: mylib and myuse. mylib.pas is a library that exports two overloaded functions Test and two Variables TestVar1 and TestVar2. Both version compile on win32 and linux but both dont work as expected.
On win32 there aren't ANY symbols exported to the DLL so myuse cant link to mylib.dll at all.
On linux at least the two functions are imported right and when I call them it works. But the imported variables aren't shared (different addresses).
Steps to reproduce:
library mylib;
{$mode objfpc}
uses
SysUtils;
var
TestVar1: Integer; public name 'TEST_VAR';
TestVar2: Integer; public name 'TestVar2';
procedure Test(S: String); stdcall; public name 'TEST_STR';
begin
WriteLn(S);
end;
procedure Test(I: Integer); stdcall; public name 'TEST_INT';
begin
WriteLn(I);
WriteLn('TestVar1 = ', TestVar1, ' @', Cardinal(@TestVar1));
WriteLn('TestVar2 = ', TestVar2, ' @', Cardinal(@TestVar2));
TestVar1 := I;
TestVar2 := I;
end;
end.
-----------------------------------------------------------------------------
program myuse;
{$mode objfpc}
var
TestVar1: Integer; external 'mylib' name 'TEST_VAR';
TestVar2: Integer; cvar; external;
procedure Test(I: Integer); stdcall; external 'mylib' name 'TEST_INT';
procedure Test(S: String); stdcall; external 'mylib' name 'TEST_STR';
begin
TestVar1 := 5;
TestVar2 := 6;
Test('FOOBAR');
Test(42);
WriteLn('TestVar1 = ', TestVar1, ' @', Cardinal(@TestVar1));
WriteLn('TestVar2 = ', TestVar2, ' @', Cardinal(@TestVar2));
end.
Additional information:
Output of myuse on linux:
FOOBAR
42
TestVar1 = 0 @3086262832
TestVar2 = 0 @3086262836
TestVar1 = 5 @134729408
TestVar2 = 6 @134729412
expected:
FOOBAR
42
TestVar1 = 5 @Addr1
TestVar2 = 6 @Addr2
TestVar1 = 42 @Addr1
TestVar2 = 42 @Addr2
Mantis conversion info:
- Mantis ID: 8397
- OS: Linux Gentoo x86
- OS Build: 2006
- Build: 6635
- Platform: Pentium3
- Version: 2.2.0
- Fixed in version: 2.2.0
- Fixed in revision: 6645 (#8d9e1389)