[fpc-pascal] Shared libries
noreply at z505.com
noreply at z505.com
Mon Dec 12 19:56:25 CET 2011
> On 2011-12-12 00:48, noreply at z505.com wrote:
>>
>>> Ok, thanks for clearifying that. I guess it's going to be a lot of
>>> include files instead... :)
>>>
>>> -Torsten.
>>
>>
>> Why do you need include files in your case?
>> You can put the units in the uses clause of your library.
> Because it is still going to give me a very long list of exports -
> considering I have approx. 200 methods to export.
>
> Instead I would do something like this:
>
> library something;
>
> {$DEFINE InterfaceSection}
> {$I unit1}
> [snip...]
> {$I unit20}
> {$UNDEFINE InterfaceSection}
>
> exports
> {$DEFINE ExportSection}
> {$I unit1},
> [snip...]
> {$I unit20}
> {$UNDEFINE ExportSection}
> ;
>
> end.
>
> unit 1;
>
> {$IFDEF InterfaceSection}
> function Foo(a: integer): integer;
> begin
> result := a * a;
> end;
> {$ENDIF}
>
> {$IFDEF ExportSection}
> Foo name 'Bar'
> {$ENDIF}
Well maybe ExportAll compiler feature should be suggested?
But please try this
unit Unit1;
{$mode objfpc}{$H+}
interface
procedure proc1; stdcall;
procedure proc2; stdcall;
implementation
procedure proc1; stdcall;
begin
writeln('hello');
end; exports proc1;
procedure proc2; stdcall;
begin
writeln('hello 2');
end; exports proc2;
end.
Notice how I put exports in several places...
It works on win32..
Try linux?
Now for your executable, load it like so:
program p;
{$mode objfpc}{$H+}
procedure proc1; stdcall; external 'd2.dll';
procedure proc2; stdcall; external 'd2.dll';
begin
writeln('First proc from lib..<enter>');
readln;
proc1;
readln;
writeln('Second proc from lib..<enter>');
proc2;
readln;
end.
More information about the fpc-pascal
mailing list