[fpc-pascal] freeBSD and GetProcedureAddress() ?
fredvs
fiens at hotmail.com
Wed Sep 3 18:35:20 CEST 2014
Hello everybody.
Good news for fpc: => this examples (with source+libraries+binaries freeBSD
64 bit) =>
>> https://sites.google.com/site/fiensprototyping/bsd_dynlib_test.tar.gz
Show that on freeBSD fpc-applications can dynamically load and run fpc and C
libraries.
1) Test with fpc libraries:
___________________________
- The fpc library:=>
library test ;
{$mode objfpc}
procedure fpctest ;cdecl;
begin
writeln('Ok, it works for fpc library...');
end;
exports
fpctest name 'fpctest';
begin
end.
__________________________
- The fpc application:=>
program getadrproc;
uses
dynlibs, SysUtils ;
var fpctest: procedure() ; cdecl;
myhandle:TLibHandle=dynlibs.NilHandle;
ordir : string;
begin
ordir := (ExtractFilePath(ParamStr(0)));
myhandle:=DynLibs.LoadLibrary(ordir + 'libtest.so');
if myhandle <> dynlibs.NilHandle then writeln('OK library loaded') else
writeln('library NOT loaded') ;
Pointer(fpctest):=DynLibs.GetProcedureAddress(myhandle,PChar('fpctest'));
if Pointer(fpctest) <> nil then writeln('OK address loaded') else
writeln('address NOT loaded') ;
fpctest();
DynLibs.UnloadLibrary(myhandle);
end.
/////////////
On my freeBSD 10 64 bit, it works ;-)
_____________________________
2) Test with C libraries:
___________________________
- The fpc application:=>
program getadrproc_c;
uses
dynlibs, SysUtils, CTypes ;
var
Pa_Initialize: function():cint32 ; cdecl;
Pa_Terminate: function():cint32 ; cdecl;
pahandle:TLibHandle=dynlibs.NilHandle;
ordir : string;
begin
ordir := ExtractFilePath(ParamStr(0));
{$IF DEFINED(linux)}
pahandle:=DynLibs.LoadLibrary(ordir + 'libportaudio_lin64.so');
{$endif}
{$IF DEFINED(freebsd)}
pahandle:=DynLibs.LoadLibrary(ordir + 'libportaudio-bsd64.so');
{$endif}
if pahandle <> dynlibs.NilHandle then writeln('OK library loaded') else
writeln('library NOT loaded') ;
Pointer(Pa_Initialize):=DynLibs.GetProcedureAddress(pahandle,PChar('Pa_Initialize'));
if Pointer(Pa_Initialize) <> nil then writeln('OK Pa_Initialize loaded')
else writeln('Pa_Initialize NOT loaded') ;
Pointer(Pa_Terminate):=DynLibs.GetProcedureAddress(pahandle,PChar('Pa_Terminate'));
if Pointer(Pa_Terminate) <> nil then writeln('OK Pa_Terminate loaded') else
writeln('Pa_Terminate NOT loaded') ;
Pa_Initialize();
Pa_Terminate();
DynLibs.UnloadLibrary(pahandle);
end.
////////////////
And it works too on freeBSD 10 64 bit ;-)
>> Conclusion: I have to check my code, why do i get that error message on
>> freeBSD and not in Linux => lot of hair and nights to loose.
PS: Sorry to disturb (and it would be easier if fpc was the guilty...)
Thanks.
Fred
-----
Many thanks ;-)
--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/freeBSD-and-GetProcedureAddress-tp5719977p5719983.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal
mailing list