[fpc-pascal]Linking with C
Michael Van Canneyt
michael.vancanneyt at wisa.be
Mon Sep 30 09:47:17 CEST 2002
On Sun, 29 Sep 2002, John Coppens wrote:
> On Sun, 29 Sep 2002 11:16:54 +0200 (CEST)
> Michael.VanCanneyt at Wisa.be wrote:
> > On Sun, 29 Sep 2002, John Coppens wrote:
> > > Hi all.
> > >
> > > I was trying to link with a C library, and everything went well till one
> > > function popped up that didn't wan't to work. Till I investigated the
> > > source library code, and found that it was in fact a macro that referenced
> > > fields from a struct.
> > >
> > > The only solution I found, was to write a few C functions that call the
> > > macro, then I link to that C proggie. Hardly elegant... Is there a another
> > > solution to this?
> > No. When we translate C library header files, we rewrite the macros always
> > as pascal functions. The h2pas conversion tool takes a shot at this, but
> > the translation always needs to be hand-tweaked.
> > Michael.
> Hello Michael.
> I wanted to avoid changing the original header files, because this seemed
> problematic: if new versions of the header files appear, it would be necessary
> to reapply the h2pas or similar step, wouldn't it?
We don't modify the headers. We translate what is possible, and rewrite
the rest as pascal functions. We do the same as you do, only we do it in
pascal, you do it in C :-)
> Writing a proper C interface avoids this problem, but means it's necessary
> to link with an extra .o file. I wonder if it would be possible to combine
> the C-generated .o and the Pascal generated .o into one lib.
You need to recompile the C interface anyway.
But yes, you can put this in one lib.
More information about the fpc-pascal