[fpc-pascal] Help needed with interfacing to C-object-files.

Koenraad Lelong koen1 at brouwerij.homelinux.net
Wed Mar 9 22:27:25 CET 2005

Marc Santhoff wrote:
> Am Di, den 08.03.2005 schrieb Koenraad Lelong um 21:51:
>>Marc Santhoff wrote:
>>>Am Mo, den 07.03.2005 schrieb Koenraad Lelong um 22:36:
>>>>I'm trying to make an interface to a kind of library, but I'm stuck. Any 
>>>>pointers are welcome.
>>>>There is a C-header file, but this is common for a number of C-modules. 
>>>>If I translate (h2pas) this file, and use it, the linker tries to find 
>>>>an o-file, which does not exist. Any suggestions how to handle this ?
>>>You've got to compile the C files to .o (gcc -c thesource.c) and then
>>>link them into your pascal unit ({$L thesource.o}). This way it should
>>>work, I'm using some C stuff like that.
>>Let me explain more : the header file is used in at least five 
>>source-files, so compiling gives (at least) five .o files, but none with 
>>the name of the header-file.
>>I was thinking that splitting that header-file in smaller files, each 
>>for its own source could do the trick, but I'll have to check this 
>>carefully. I had hoped for another suggestion.
>>Anyway, thanks for the response.
> Hm, I don't know, how the translated header looks in pascal, but if it's
> a complete unit itself you could try to {$L xxx} all resulting .o files
> in that unit. So any declared function and type should be found ... the
> other thing would be, if the sources from the 1-wire stuff form a
> dynamic library, then you simply have to tell the linker to pull this
> lib (.so) in
> fpc -k-l<thelibraryname without the.so-ending> ...
> should work and does for me, too. Or it needs an additional
> "-k-L/the/path/to/1-wire-lib". The only thing in your sources is to put
> the translated header in the uses clause.
> HTH,
> Marc
I put some files on http://users.edpnet.be/~koenraad.
ulinuxgnu300.zip is the original file from DallasSemiconductor, with the 
ownet.h.tar.gz contains the "problem" header file, in C en "raw" h2pas, 
and two other header files used by temp.c, with their h2pas 
counterparts, and finally the temp.c-file which I'm trying to implement 
is FPC, as a testcase.
Finally temp1.pas.tar.gz contains my FPC-versions of the header-files, 
cleaned up somewhat, so I could successfully compile. Of course this 
needs more work to make it usefull.
If I compile without an o-path (-Fo), findtype.o and temp10.o are not 
found and of course ownet.o. If I add a path to the files findtype.o and 
temp10.o only ownet.o is not found, because it does not exist.
Let me say that I'm new to programming for Linux, and to programming 
with FPC. I do use Delphi at work, so I know something of Pascal, 
although I'm not an expert.
Thanks for any help,

More information about the fpc-pascal mailing list