[fpc-devel] Cross compiling x86 on amd64, linking to crtbegin.o etc.

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Jul 17 00:51:27 CEST 2012


On 17 Jul 2012, at 00:36, Konstantin wrote:

> The bad thing is
> that these paths are determined by the FPC function
> librarysearchpath.FindFile and as this function does not honor the
> target architecture. It always returns /usr/lib/..... as the default
> architecture version of these files is located there. This of course
> fails when compiling 32 bit on a 64 bit Gentoo machine where the 32 bit
> versions are in /usr/lib32/..... and linking fails due to invalid files.
> 
> So again my second question is, why are absolute paths used for
> crtbegin.o, crti.o, crtend.o and crtn.o?

Because based on the information provided to the compiler via command line parameters and the knowledge hardcoded into the compiler, those are the files that should be linked. Specifying their explicit path ensures that the linker will link the object files that compiler wants it to link, rather than some random files with the same names that the linker find somewhere else. Those files may be the wrong ones in your particular scenario, but most cases this strategy will prevent the exact opposite problem.

What you can do is add something like this to the default configuration file on 64 bit hosts:

#ifdef cpui386
#ifdef linux
# prevent searching the default library directories
-Xd
# add the 32 bit-specific library directories
-Fl/usr/lib32
-Fl/other/32bit/directory
#endif
#endif

Patching the compiler source should not be necessary.


Jonas


More information about the fpc-devel mailing list