How to use the Dynamic Shared Object in Lazarus? lazarus / 13-General ---------------------------------------------------------------------- VictorZhang · 2007-02-26 17:54 How to use the Dynamic Shared Object(SO on Linux) Without an Import Library(e.g:function Add (A:Integer;B:Integer):Integer;cdecl ;external 'libMyFirstSO.so'; ) in Lazarus(on Linux)? I try the codes below which can run in Kylix , but they cannot work in Lazarus. unit DynaForm; interface uses SysUtils,Classes,Qcontrols,Qforms; type   TForm1 = class(TForm)     Button1: TButton;     procedure Button1Click(Sender: TObject); end; var  Form1:TForm1; implementation {$R *.XFM} type  TComputeInteger= function (x:Integer;y:Integer):Integer;cdecl; procedure TForm1.Button1Click(Sender:TObject); var Handle :Thandle ;    Compute:TcomputeInteger; begin   Handle:=LoadLibrary('libMyFirstSO.so');   if Handle<>0 then   begin     Compute:=TcomputeInteger(GetProcAddress(Handle,'Add'));     if Assigned(Compute) then        ShowMessage(IntToStr(Compute(10,20));     FreeLibrary(Handle);   end   else     ShowMessage('Library not found'); end; procedure TForm1.Button1Click(Sender:TObject); var Handle :Pointer ;    Compute :TcomputeInteger; begin   Handle:= dlopen('libMyFirstSO.so');   if Handle<>nil then   begin     Compute:=TcomputeInteger(dlsym(Handle,'Add'));     if Assigned(Compute) then        ShowMessage(IntToStr(Compute(10,20));     dlclose(Handle);   end   else     ShowMessage('Library not found'); end; ---------------------------------------------------------------------- felipemdc · 2007-02-26 18:10 Change QControls to controls and QForms to forms. Also add dynlibs (I think that´s what it´s called, but I could be wrong) to uses clause. Do not use dlopen, just use LoadLibrary, GetProcAddress and FreeLibrary like in Windows (but without windows on uses clause). Dynlibs implements those functions in a cross-platform way. Now try to compile again. ---------------------------------------------------------------------- VictorZhang · 2007-03-01 15:11 "dynlibs" is OK.Thanks. Code: [Select] {$MODE OBJFPC} unit dynlibs; interface { ---------------------------------------------------------------------   Read OS-dependent interface declarations.   ---------------------------------------------------------------------} {$define readinterface} {$i dynlibs.inc} {$undef  readinterface} { ---------------------------------------------------------------------   OS - Independent declarations.   ---------------------------------------------------------------------} Function LoadLibrary(Name : AnsiString) : TLibHandle; Function GetProcedureAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer; Function UnloadLibrary(Lib : TLibHandle) : Boolean; // Kylix/Delphi compability Function FreeLibrary(Lib : TLibHandle) : Boolean; Function GetProcAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer; Type   HModule = TLibHandle; Implementation { ---------------------------------------------------------------------   OS - Independent declarations.   ---------------------------------------------------------------------} {$i dynlibs.inc} Function FreeLibrary(Lib : TLibHandle) : Boolean; begin   Result:=UnloadLibrary(lib); end; Function GetProcAddress(Lib : TlibHandle; ProcName : AnsiString) : Pointer; begin   Result:=GetProcedureAddress(Lib,Procname); end; end.