[fpc-pascal]dll (with c convention) under win and linux
Alexis Halbot-Schoonaert
a.halbotschoonaert at free.fr
Sun Oct 29 18:31:36 CET 2000
Hello,
I wanted to trye to build my own dll.
I wanted it to be usable under win32 and linux.
So, i used the sample provided with fpc for win.
Compiled under windows, no problem. I had to adapt it to linux and tried
to compile. No problem.
But, when i run the program (under linux), i have this message :
./dlltest: error in loading shared libraries:
libtestdll.so: cannot open shared object file:
No such directory
Though, libtestdll.so is in the same directory than dlltest. I tried to
copy libtestdll.so in /usr/sbin, and i have the same problem. So,
supposed it was not because of the path...
Could you tell me what is wrong ?
And i'd like the main program and the library to use the c call
convention (with cdecl ?). What is the way to do it ?
This is the modified source :
program dlltest;
procedure p1(x:pointer); external 'testdll' name 'P1';
procedure proc2(x:longint); external 'testdll' name 'Proc2';
var s : string;
begin
s:='';
writeln('Main: Hello!');
p1(nil);
//writeln('Main: ',Hinstance,' ',Hprevinst);
writeln('Main: testdll s string = ',s);
s:='Changed by program';
proc2(1234);
writeln('Main: press enter');
readln;
end.
library testdll;
var teststr : string;
procedure P1(var s:string);export;
var p:array[0..255] of char;
begin
length(s);
end;
procedure P2(x:longint);export;
begin
writeln('DLL: Argument X=',x);
writeln('DLL: New teststr="',teststr,'"');
end;
procedure P3(var t);export;
var
p : pointer;
begin
p:=Addr(T);
p:=p;
end;
procedure P4(x1:pointer);export;
begin
Inc(x1);
end;
procedure NewExit;
begin
writeln('DLL: Exit from testdll');
end;
exports
P1 name 'P1',
P2 name 'Proc2',
P3,
P4 resident; //,
//teststr name 'FPC_string';
begin
//writeln('DLL: HInstance ',Hinstance,' PrevInst ',Hprevinst,'
DLLReason ',DLLreason,' DLLParam ',DLLparam);
teststr:='DLL init done';
exitproc:=@newExit;
end.
Thank you for your help.
Reguards,
Alexis.
More information about the fpc-pascal
mailing list