[fpc-pascal] Mangle name in fpc-FreeBSD ?
Marc Santhoff
M.Santhoff at web.de
Sun Mar 20 08:04:36 CET 2016
On Sa, 2016-03-19 at 14:39 -0700, fredvs wrote:
> @ Marco and Marc thanks for help.
>
> Sorry I do not have easy internet connection so I worked by my side.
>
> I will try your tips.
>
> By the way, here are my investigations:
>
> ____________________________________
>
> Hello.
>
> Ok, ok, understood and wow.
>
> Added in code:
>
> Function dlopen(filename: PChar; flags: cint): Pointer; cdecl; external;
> Function dlclose(handle: Pointer): cint; cdecl; external;
> Function dlsym(handle: Pointer; Name: PChar): Pointer; cdecl; external;
> Function dlerror: PChar; cdecl; external;
>
> and, magic, it works. ;-)
>
> Now the result:
>
> In code:
>
> procedure loadmylib(lib : pchar);
> var
> ap1, ap2, ap3 : pointer;
> '
> begin
> /// FreeBSD functions:
> ap1 := dlopen(Pchar(lib), 0);
Here you are using 0 for three mode argument. One difference I can see
ist that uysing dynlibs.pas the mode is RTLD_LAZY like it should be, but
that constant is defined as 1.
Does anyone now if this really makes a difference?
> if ap1 <> nil then
> writeln('dlopen() is OK') else
> writeln('dlopen() is NOT OK') ;
>
> ap2 := dlsym(ap1, Pchar('mp4ff_open_read');
> if ap2 <> nil then
> writeln('dlsym() is OK') else
> writeln('dlsym() is NOT OK') ;
>
> writeln(dlerror());
>
> end;
>
> ---> result:
> writeln('dlopen() is OK')
> writeln('dlsym() is OK')
> _ (no error)
>
> --------------------------------------
> Now with DynLibs:
>
> procedure loadmylib(lib : pchar);
> var
> ap1: pointer;
> hn : integer;
> '
> begin
> /// with dynlibs
> hn := dynlibs.loadlibrary(Pchar(lib));
>
> if hn <> 0 then
> writeln('loadlibrary() is OK') else
> writeln('loadlibrary() is NOT OK') ;
>
> ap1 := getprocedureaddress(hn, Pchar('mp4ff_open_read');
>
> if ap1 <> nil then
> writeln('getprocedureaddress() is OK') else
> writeln('getprocedureaddress() is NOT OK') ;
Looking at dynlibs.pas you can use
Function GetLoadErrorStr: string;
here. Or simply dlerror() like in the other program, should work.
> end;
>
> --> result:
>
> loadlibrary() is OK
> getprocedureaddress() is NOT OK
>
> ............
>
> Conclusion: Maybe getprocedureaddress() has problems.
--
Marc Santhoff <M.Santhoff at web.de>
More information about the fpc-pascal
mailing list