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

Koenraad Lelong koen1 at brouwerij.homelinux.net
Sat Mar 12 17:23:41 CET 2005

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}
> {$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}
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'
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.
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.
Maybe I'm too used to using Delphi, where such things are hidden from 
the developper.

More information about the fpc-pascal mailing list