Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-09

freeBSD and GetProcedureAddress() ?

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

fredvs

Hello everybody.

Hum, i try to dynamically load (and run) some freeBSD libraries with a fpc-freeBSD-appliction.

For testing, i use some library included in /usr/lib (so im sure that the library is working on freeBSD).

Those test is fully working with Linux.

I can load the library with DynLibs.LoadLibrary(libfilename) in feeBSD.

I can get the procedure address with DynLibs.GetProcedureAddress() in freeBSD => pointer
is nil. => seems ok.

But if i try to use that procedure, fpc application crash (without any useful
message from debugger).

Now the questions:
1) Has somebody try to make a fpc application that use dynamically loaded libraries in freeBSD?
2) If yes, what was the result, was it OK ?
3) If 2) = OK => how did you do it ?

Many thanks.

Fredf

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/freeBSD-and-GetProcedureAddress-tp5719977.html Sent from the Free Pascal - General mailing list .

Reply by email

Reinier Olislagers
to fredvs
fredvs wrote 5 lines
Hum, i try to dynamically load (and run) some freeBSD libraries with a fpc-freeBSD-appliction. For testing, i use some library included in /usr/lib (so im sure that the library is working on freeBSD).

Why not go crazy and post (a link to) the actual code of this test program? Perhaps people can spot errors just by looking at the code...

Reply by email

Marco van de Voort
to Reinier Olislagers

In our previous episode, Reinier Olislagers said:

Show quoted text 9 lines
On 03/09/2014 13:28, fredvs wrote: > Hum, i try to dynamically load (and run) some freeBSD libraries with a > fpc-freeBSD-appliction. > > For testing, i use some library included in /usr/lib (so im sure that the > library is working on freeBSD). Why not go crazy and post (a link to) the actual code of this test program? Perhaps people can spot errors just by looking at the code...

Along with the output

file <the program you compiled>

and

file <the .so that you try to load>

to guard against 32 vs 64-bit issues.

Reply by email

fredvs
to Reinier Olislagers: Why not go crazy and post (a link to) the actual code of this test program? Perhaps…
> Why not go crazy and post (a link to) the actual code of this test

program?

;-) => ok, i will stay crazy...

> Perhaps people can spot errors just by looking at the code...

Hum, i hope for those people (but im sure there are, sadly, no errors) ...

Write you later.

PS: Is fpc still maintaining freeBSD compatibility ?

Thanks.

Fred

-----
Many thanks ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/freeBSD-and-GetProcedureAddress-tp5719977p5719980.html Sent from the Free Pascal - General mailing list .

Reply by email

Tomas Hajny
to fredvs

On Wed, September 3, 2014 13:51, fredvs wrote:
.
.

>> Perhaps people can spot errors just by looking at the code... Hum, i hope for those people (but im sure there are, sadly, no errors) ...

Never say 'never'... ;-)

.
.

PS: Is fpc still maintaining freeBSD compatibility ?

Isn't answer to this question clear from explicit information on FPC WWW pages and implicitly e.g. from the list of platforms supported in the latest release?

Tomas

Reply by email

Reinier Olislagers
to fredvs: program? ;-) => ok, i will stay crazy... Hum, i hope for those people (but im sure there…
fredvs wrote 8 lines
>> Why not go crazy and post (a link to) the actual code of this test program? ;-) => ok, i will stay crazy... >> Perhaps people can spot errors just by looking at the code... Hum, i hope for those people (but im sure there are, sadly, no errors) ...

Sigh...
http://catb.org/~esr/faqs/smart-questions.html
and
http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Let's say your code is 100% correct. In that case, it can serve as a test case for others to verify the bug and a test case in a bug report (and regression test).
Writing that you have created a small test program without including it is IMO not very productive...

If your code isn't 100% correct... well, obviously nobody will find out unless you publish it.

Reply by email

fredvs
to Reinier Olislagers

Hello everybody.

Good news for fpc: => this examples (with source+libraries+binaries freeBSD 64 bit) =>

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 .

Reply by email