[fpc-pascal] static binding to C shared library (linux)
Alain Michaud
Alain.Michaud at nrc-cnrc.gc.ca
Mon Jan 23 17:52:15 CET 2006
Hi,
Thank you to you all. After I wrote the declaration just like given
below, I had the library linked to my pascal program, and did not even
need to spend the week end on it! :)
Thanks again to you all.
Alain Michaud
On Tue, 2006-01-17 at 10:34 +0200, Гено Рупски wrote:
> В пн, 2006-01-16 в 23:07 -0500, Alain Michaud написа:
> > This makes me think that it has to do with the parameters. This one has
> > three. Unfortunately there is no other 'simple' function in the
> > library:
> >
> > int pl_setplparam (plPlotterParams * plotter_params, const char
> > *parameter, void *value)
> >
> > which I translate into:
> >
> > function pl_setplparam (plotter_params:plplotterparams; const
> > parameter:PCHAR; value:PCHAR):cint; cdecl; external 'plot';
>
> The proper function declarations should be:
>
> type
> PPlPlotterParams = Pointer;
>
> function pl_newplparams: PPlPlotterParams; cdecl; external 'plot';
>
> function pl_setplparam(plotter_params: PPlPlotterParams; parameter:
> PChar; value: PChar): longint; cdecl; external 'plot';
>
> note that PPlPlotterParams is declared as pointer. It's easiest way when
> you don't care what is the structure it is pointing to. Also notice that
> the second parameter is desclared without const this is due to pascal
> tranforming const parameters into pointers which is equivalent as
> declaring second parameter as "parameter: PPChar".
> >
> > please look at the last two parameters: one is "const" while the other
> > is not. Does that looks OK to you? Should I always use the same variable
> > names as the .h file? What should I do with the f... "void"?
>
> parameters names (even procedure names when using name) does not matter.
> it only matters the parameters' types and calling convention.
>
> >
> > 2 - Someone tells me that old compilers would accept " * int" while the
> > new compilers would prefer a variable name: "variable * int" or "void *
> > int". Unless this the other way around then I should not use the
> > NO_VOID_SUPORT. So I guess I do not worry about that one any more.
>
> you don't have to worry because in both ways the resulting lib is
> compatible with your declaration.
>
> >
> > 3 - The file I have is "libplot.so" I think that this is a shared
> > library. Does that coresponds to "cdecl; external 'plot';"? If not, then
> > this is where my mistake was!!!!!!!
>
> yes it is a shared library it corresponds to "cdecl; external 'plot';"
> >
> > Is: external 'plot'; equivalent to: {$L liplot.so} or: {$Linklib
> > liplot.so} ?
>
> external 'plot' - tells the linker in which lib to search for the
> function while using {$L} or {$linklib} adds the library and when you
> declare a function as external without specifying where it is located
> the linker searches for the name in all libraries
>
> Also please see the program h2pas in the utils section of free pascal.
> It makes translation from headers to pascal very easy,
>
> TIA,
> Geno Roupsky
>
More information about the fpc-pascal
mailing list