[fpc-pascal] static binding to C shared library (linux)

Alain Michaud Alain.Michaud at nrc-cnrc.gc.ca
Mon Jan 16 23:41:06 CET 2006


Hi,

 I would apreciate if someone could give me some advice please. In this
example:

cfunction = function(theparameter:cint):cint;cdecl;external'theclib'; 

It seems that this will not build unless I have the
file: /usr/local/include/theclib.h  

1-Is this true?
2-Does the FPC compiler read this .h file?
3-Does the linker read this file?
 

The C prototypes for the two functions that I want to use look like
this:

plPlotterParams * pl_newplparams(void)

or:

plPlotterParams * pl_newplparams

and:

int pl_setplparam (plPlotterParams * plotter_params, const char
*parameter, void *value)

or:
 
int pl_setplparam (plPlotterParams * plotter_params, const char
*parameter, char *value)
 
The two set of prototypes exists because of a switch: "NO_VOID_SUPPORT"
to accept different compilers. 

1 - Does anyone knows which case my compiler uses? "void" or "no_void"?


The first function "pl_newplparams" is suposed to allocate a structure
then return a handle. It seems that it returns something different than
"nil" but I am not sure if it is valid however.

This pointer is used as a parameter for the second function
"pl_setplparam". 

ERR := pl_setplparam(plotter_param,'PAGESIZE','letter'); 

As soon as I call the function I get an "access" exception at the offset
000000000. Although the function has 3 parameters, it could be the first
one (the pointer) that has the wrong type!

I have tried many things like this:

type
plplotterparams = record end;

function pl_newplparams:plplotterparams; cdecl; external 'plot';

function pl_setplparam (plotter_params:plplotterparams; const
parameter:PCHAR; value:PCHAR):cint; cdecl; external 'plot';
 
Can someone give me some hints on how to solve that problem. I have
spent the whole week-end on these three lines and I am quite frustrated
right now!  The package is called "libplot" ("plotutils") and I was
planning to put it on the web if I can get it to work. :(

May be there is a book, documentation or an example file that I could
use and was not aware of?

Thank you for reading

Alain Michaud






More information about the fpc-pascal mailing list