[fpc-pascal] Cross linking

Marco van de Voort marcov at stack.nl
Mon Jan 17 22:52:17 CET 2005


People on IRC might already have noticed, but I was playing a bit with 
crosscompiling from mingw->*nix. The first successes are in, though this
is only the initial procedure.

To compile linux lazarus on windows: (the procedure from freebsd will not
differ much, the cprt0 copying is not needed for FreeBSD)

Requirements:
- FPC 1.9.6 or higher. 1.9.4 migh work, but untested.
- ftp://freepascal.stack.nl/pub/fpc/contrib/cross/mingw/binutils-2.15-win32-i386-linux.zip
- A FPC CVS repository.  (anything 1.9.6+ that is buildable will do)
- a lazarus tree. (anything buildable from the same period will do)
- Lots of libraries from the target linux system. One of the FPC servers is some SUSE, 
	that's what I used, but it should be pretty generic. 
- Assume normally installed FPC, and being able to build e.g. lazarus on windows
- some knowledge about how libs are named on linux.

Additional docs:
- lazarus docs, specially what libs are needed to build lazarus
- buildfaq http://www.stack.nl/~marcov/buildfaq.pdf can be examined
	if something goes wrong and for background info.

1) Download ftp://freepascal.stack.nl/pub/fpc/contrib/cross/mingw/binutils-2.15-win32-i386-linux.zip
2) extract it and move the i386* files to <fpcbindir>\bin\i386-win32  
	(e.g. c:\pp\bin\i386\win32)
3) enter FPC source dir
4) make clean 
5) make OS_TARGET=linux all
6) make OS_TARGET=linux install INSTALL_PREFIX=<fpcbindir>
7) prepare the lib directory as in below instructions,  I used d:\fpc\linuxlib to store them.
8) go to <fpcbindir>\units\i386-linux\rtl  and copy cprt21.o over cprt0.o
9) enter lazarus dir
10) edit lazarus.pp and add {$linklib dl} and {$linklib gmodule} somewhere in the source.
11) (on one line) make OS_TARGET=linux all 
	OPT="-gl -Fld:\fpc\linuxlib -Xr/usr/lib -FL/usr/lib/ld-linux.so.2 " 

If some linker error (most specifically linker can't find -l<something>) then

12) manually edit link.res if needed (see below for gtk remarks) and adapt the -l<x> names at the bottom of the files. I had to add -1.2 to all gtk
    libs, to keep them apart from gtk2
13) run ppas.bat to restart the linker

----------- Libraries

These are the libraries I collected for both lazarus and the textmode IDE
(lazarus doesn't need pthread).

I gathered these from the target system, and renamed all from
lib<name>.so.x.y to lib<name>.so.

libgcc.a and a few others are easiest found by doing gcc -v and look for a
line like:
"Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs"
then some of the libs are in  /usr/lib/gcc-lib/i486-linux/3.3.5/ 

Some other good locations are /lib /usr/lib /usr/local/lib /usr/x11R6/lib
and /opt/gnome/lib

libpthread.so.0
libdl.so
libc.so
ld-linux.so.2
crtbegin.o
crtbeginS.o
crtbeginT.o
crtend.o
crtendS.o
crtn.o
crti.o
libgcc.a
libX11.so
libXi.so
libglib-1.2.so
libgmodule-1.2.so.0
libgdk_pixbuf.so
libgdk-1.2.so
libgtk-1.2.so
libXext.so
libm.so
libdl.so.2
libgmodule-1.2.so

Note that some files exist twice, with a .so.x suffix and just .so. These are
required because some other lib had a dependancy to that exact name (so the
form lib<name>.so.x) we can't symlink on windows, so I simply copied it.

Making mistakes with renaming is not that bad, there will be chances to fix
it. Make sure all crt* and a file "libc.so" are available before your first
attempt, otherwise generating link.res will go wrong. (Yes, Peter, that was
my fault with the crt<x> files, forgot the -Fl :-)

libgcc.a is the only .a

In my case compilation for step 11 will go ok, but the linker will complain
it can't find libgtk.so and the other libraries marked with -1.2 This is
because on the target system, libgtk is gtk 2.0, while we want gtk1.2 for
lazarus.

To fix this I manually added -1.2 to the corresponding -l lines in the
bottom of the link.res file that was generated by step 11 and reran ppas.bat

I crosscompiled the texmode IDE also this way, same tricks, only you need
ncurses as extra lib. I also crosscompiled the threading demo "tmt1"




More information about the fpc-pascal mailing list