[fpc-pascal] Search order for libraries, how to influence; using GMP

Tom Verhoeff T.Verhoeff at tue.nl
Tue Jun 12 23:06:10 CEST 2007

I am trying to use the GNU Multi-Precision (GMP) library with
FreePascal under Linux.

I have a Pascal interface for GMP (originally for Kylix; translated
from C header file).

The header file libgmp.pas and my using program testgmp.pas compile fine.

But linking fails.  The message is

/usr/bin/ld: skipping incompatible /usr/lib/crti.o when searching for /usr/lib/crti.o
/usr/bin/ld: cannot find /usr/lib/crti.o

This might be caused by the fact that I use a 64-bit machine with
a 32-bit version of FPC.

For that reason, I added the command-line option:


Without this option, I get the message

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/4.1.1/crtbegin.o when searching for /usr/lib/gcc/x86_64-pc-linux-gnu/4.1.1/crtbegin.o
/usr/bin/ld: cannot find /usr/lib/gcc/x86_64-pc-linux-gnu/4.1.1/crtbegin.o

With the option, it does find the appropriate crtbegin.o.

Therefore, I also added the command-line option


But this does not help, since /usr/lib is searched first and there if
finds the incompatible (64-bit?) version of crti.o, and fails.

How can I force the linker to look in /usr/lib32 before /usr/lib ?

When inspecting link.res, it starts out


Apparently, the first three are forced 'out of nowhere', then there are
the two options from the command line, and then the one from /etc/fpc.cfg,
followed by a long list of directories named /usr/lib/fpc/* .

Where do the first three come from?  Can those be (re)moved?


E-MAIL: T.Verhoeff @ TUE.NL     | Dept. of Math. & Comp. Science
PHONE:  +31 40 247 41 25        | Technische Universiteit Eindhoven
FAX:    +31 40 247 54 04        | PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/  | The Netherlands

More information about the fpc-pascal mailing list