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

Marc Santhoff M.Santhoff at t-online.de
Sat Mar 12 21:20:35 CET 2005

Am Sa, den 12.03.2005 schrieb Koenraad Lelong um 18:53:
> Jeff Pohlmeyer wrote:
> >>My question : is the linker not smart enough to find out 
> >>by itself where to look for those missing object files ?
> > 
> > 
> > Not sure if I understand your question, but as Marc already 
> > mentioned, you can control this with the -k-L compiler switch. 
> > 
> > You can also control the way the compiler/linker searches
> > for various things using directives, eg:
> > 
> > {$OBJECTPATH path}
> > {$LIBRARYPATH path}
> > {$UNITPATH path}
> > 
> > 
> >  - Jeff
> > 
> > 
> > 
> OK, maybe you need more information. This is how I compile :
> ppc386 -g -Sd -Fo/home/koenraad/owpd300 temp1
> My program temp1 'uses' ownet.
> In ownet.pp there are a number of routines that are in c-object files.
> I include these object files with :
> {$L owerr.o}
> {$L ownetu.o}
> etc.
> If I compile this I get errors about not finding things used in 
> ownetu.o, e.g. (exact quote) :
> /home/koenraad/owpd300/ownetu.o(.text+0xea): In function 'owNext':
> : undefined reference to 'UMode'
> etc.
> If I look in ownetu.c I see :
> #include "ownet.h"
> #include "ds2480.h"
> So I added in ownet.pp :
> {$L ds2480.o}
> then the errors about ownetu.o are gone. Likewise I have to add several 
> other object files not directly used in ownet.pp, but used in files that 
> are linked with {$L...}.
> All those object files are in /home/koenraad/owpd300.
> I assumed that when a routine uses some code in an object file which in 
> turn uses code in another object file, the linker would be smart enough 
> to know to look for that second object file. Of course, if those object 
> files are not in the search-path they will not be found.
> Actually, when I add -va to the compile command, I see that the compiler 
> searches in a number of paths for code that is used. Why doesn't the 
> linker do the same ? My first tought would even be that I do not have to 
> add those first {$L...}'s.

Since I have not enough knowledge about the linkers inner details and
about fpc's usage of it I can only advise you to have a look at the
original Makefile of the object files in question. The line and
variables envolved in linking the 1-wire files should give you some
hints on their dependencies.

If anything else fails you could translate the included headers
("ds2480.h" in this case) too and add them to the uses clause ...

> Maybe these questions have nothing to do with fpc, but I'm trying to 
> understand, so I don't make these errors in the future. If this is 
> explained somewhere, do please give me some pointers.

I think you should read the man page of the linker.

> Maybe I'm too used to using Delphi, where such things are hidden from 
> the developper.

That's the nice part of Delphi. :)


More information about the fpc-pascal mailing list