Difference between revisions of "Cross compiling/pt"

From Free Pascal wiki
Jump to navigationJump to search
Line 83: Line 83:
 
==Para Linux==
 
==Para Linux==
 
Marco vd Voort wrote some [http://www.stack.nl/~marcov/crossnotes.txt crossnotes]. If somebody has time, he can add them to this wiki.
 
Marco vd Voort wrote some [http://www.stack.nl/~marcov/crossnotes.txt crossnotes]. If somebody has time, he can add them to this wiki.
 +
 +
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 where I got the list below.
 +
 +
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) 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 directories are duplicate, with a suffix and not. These are required because some other lib has a dependancy on that
 +
exact name (so the form lib<name>.so.x) we can't symlink on windows, so I simply copy 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, otherwise
 +
generating link.res will go wrong. (Yes, Peter, that was my mistake :-)
 +
 +
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
 +
 +
P.s.
 +
a lot of linker editing _can_ be resolved with the beta linker control
 +
switches (-XLA and friends) in 2.0.4 and 2.1.1 . However these are beta,
 +
undocumented and not necessary available in future versions. They were
 +
mostly added to give package builders ( for linux distro's) and
 +
crosscompilers a chance to evaluate possible option.
 +
 +
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 where I got the list below.
 +
 +
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) 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 directories are duplicate, with a suffix and not. These are required because some other lib has a dependancy on that
 +
exact name (so the form lib<name>.so.x) we can't symlink on windows, so I simply copy 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, otherwise
 +
generating link.res will go wrong. (Yes, Peter, that was my mistake :-)
 +
 +
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
 +
 +
P.s.
 +
a lot of linker editing _can_ be resolved with the beta linker control
 +
switches (-XLA and friends) in 2.0.4 and 2.1.1 . However these are beta,
 +
undocumented and not necessary available in future versions. They were
 +
mostly added to give package builders ( for linux distro's) and
 +
crosscompilers a chance to evaluate possible option.
  
 
=From Darwin (Mac OS X) i386=
 
=From Darwin (Mac OS X) i386=

Revision as of 16:31, 18 April 2007

Deutsch (de) English (en) español (es) français (fr) magyar (hu) português (pt) русский (ru) 中文(中国大陆)‎ (zh_CN) 中文(台灣)‎ (zh_TW)

Introdução

Esta é uma curta introdução para novatos. As seções seguintes descrevem como configurar um sistema para cross-compilação, isto é, trabalhar no Linux and criar executáveis para Win32 (ou FreeBSD, Darwin, etc.). O FreePascal é um compilador e basicamente converte código em binário (linguagem de máquina). Os binários também contêm informação sobre como o sistema operacional inicia o executável. Portanto os binários são específicos para cada plataforma. O FreePascal em si mesmo não precisa de muita configuração. Ele pode criar binários para muitas plataformas. Somente lhe diga para fazer isso. Mas o compilador é somente uma parte. Existe também o assembler e o vinculador, e essas ferramentas não são capazes de criar código cross-plataforma. É por isso que nós precisamos criar vinculadores especiais 'ld' e assembler 'as' para cada plataforma-alvo. Essas são as binutils. Depois de criar as ferramentas cross-plataforma, todas as unidades Pascal do FPC serão cross-compiladas. Por exemplo, existe um system.ppu para cada plataforma-alvo. Assim o seu arquivo de configuração do FPC será configurado de forma que a cross-compilação se torne tão fácil que você esquecer todos os detalhes aborrecidos. O mesmo será feito para a LCL - a biblioteca de componentes do Lazarus. E depois disso você pode fazer cross-compilação de seus programas Pascal para Win32. Ou iniciá-los no Wine ou copiá-los para uma máquina Windows e testá-los.

Passos Básicos

Existem uns poucos passos em comum implicados em cross-compilação que você precisa cumprir em cada caso:

  1. Ter um compilador FreePascal para a plataforma em que você quer compilar.
  2. Ter o código-fonte do FreePascal.
  3. Ou construí-lo dos fontes ou obter os binários das cross-binutils que executem na plataforma em que você está e são desenhadas para construir programas para a plataforma-alvo desejada.
  4. Às vezes você vai precisar de alguns arquivos da plataforma para onde está compilando.

De Linux

Para Linux

Fique claro que isso é para compilar de Linux(x86_64) para Linux((i386).

Há chances de a sua distribuição Linux 64 bits já possibilitar a compilação de programas 32 bits mas devido à maneira como o processo de construção do FPC é desenhado existem algumas coisas que você vai precisar fazer:

  • Primeiro cheque se você já tem os arquivos i386-linux-ld e i386-linux-as:
 bash $ which i386-linux-ld
 bash $ which i386-linux-as

Se você tem esses arquivos, pule para o título "Compilar o FPC". Se você não tem os arquivos, eu fiz alguns scripts:

#!/bin/bash
# name this file /usr/bin/i386-linux-ld
ld -A elf32-i386 $@
#!/bin/bash
# name this file /usr/bin/i386-linux-as
as --32 $@
  • Fazê-los um executável:
bash $ chmod +x /usr/bin/i386-linux-as
bash $ chmod +x /usr/bin/i386-linux-ld
  • Compilar o FPC:
bash $ make all CPU_TARGET=i386

então:

bash $ su -c "make install CPU_TARGET=i386"

É isso. Edite seu arquivo /etc/fpc.cfg se necessário.

Para Windows

How-to oficial Cross_compiling_for_Win32_under_Linux
How-to para Lazarus 0.9.22 e FPC 2.0.4 http://fdavid.com.br/blog/?p=4

Se você está compilando a versão 2.1.1 ou superior do FPC, você pode apenas fazer:

bash $ make all OS_TARGET=win32 CPU_TARGET=i386

e então

bash $ su -c "make crossinstall OS_TARGET=win32 CPU_TARGET=i386"

Nota: para construir para Win64, o comando make é: make all OS TARGET=win64 CPU_TARGET=x86_64

A razão dessa simplicidade é o vinculador interno incluído nessa versão do FPC.

Para Darwin ou Mac OS X

  • Primeiro você precisa das binutils para a plataforma para a qual você quer compiilar. Baixe o odcctools deste site (use a versão CVS) e siga as instruções de instalação. http://www.opendarwin.org/projects/odcctools/
  • Você precisa criar um falso diretório root, como: $HOME/darwinroot. Copie pelo menos os diretórios /System e/Frameworks e /usr (você deve ter que copiar mais do que isso) do seu computador Aple ou Darwin para $HOME/darwinroot.
  • Agora que você tem esses arquivos, crie uma pasta em $HOME/darwinroot chamada cross. Em qualquer lugar que você tenha instalado o odcctools você precisa fazer links for the cross tools to be more fpc friendly. Existe um grupo de arquivos de ferramentas odcc chamado powerpc-apple-darwin-*. Você precisa fazer links (ou renomeá-los) de modo que o powerpc-apple-darwin-ld se torne powerpc-darwin-ld. Faça o mesmo com *-ar *-as.
  • Agora você está pronto para cross-compilar o FPC. Basicamente você precisa ter o código-fonte do FPC e uma janela de terminal aberta.

Escreva:

$PATH=$PATH:$HOME/darwinroot/cross (ou onde você fez os symlinks)

Escreva (iirc):

make all TARGET_OS=darwin TARGET_CPU=powerpc OPT="-Xd -Fl/$HOME/darwinroot/usr/lib"

Se isso der certo você pode instalá-lo em qualquer lugar que queira com:

make install TARGET_OS=darwin TARGET_CPU=powerpc PREFIX=/cross/fpc

Agora copie o arquivo ./compiler/ppccross para onde você possa achá-lo, pois esse é o compilador que você vai precisar para construir programas para PowerPC.

  • Configure o seu arquivo /etc/fpc.cfg.

Adicionne uma seção como essa:

#IFDEF powerpc
-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/
-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
-Fu/cross/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
-k-systemroot $HOME/darwin/cross
#ENDIF

Sempre que você queira cross-compilar você precisa ter o ppccross e os symlinks para powerpc-darwin-* no seu Path. E você deve poder fazer o pcccross someprogie.pas e ele vai criar o executável Darwin.

Eu posso ter errado alguma coisa (ou quase tudo) as it's been a while pois eu fiz assim.

De Windows

Para Linux

Marco vd Voort wrote some crossnotes. If somebody has time, he can add them to this wiki.

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 where I got the list below.

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) 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 directories are duplicate, with a suffix and not. These are required because some other lib has a dependancy on that exact name (so the form lib<name>.so.x) we can't symlink on windows, so I simply copy 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, otherwise generating link.res will go wrong. (Yes, Peter, that was my mistake :-)

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

P.s. a lot of linker editing _can_ be resolved with the beta linker control switches (-XLA and friends) in 2.0.4 and 2.1.1 . However these are beta, undocumented and not necessary available in future versions. They were mostly added to give package builders ( for linux distro's) and crosscompilers a chance to evaluate possible option.

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 where I got the list below.

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) 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 directories are duplicate, with a suffix and not. These are required because some other lib has a dependancy on that exact name (so the form lib<name>.so.x) we can't symlink on windows, so I simply copy 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, otherwise generating link.res will go wrong. (Yes, Peter, that was my mistake :-)

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

P.s. a lot of linker editing _can_ be resolved with the beta linker control switches (-XLA and friends) in 2.0.4 and 2.1.1 . However these are beta, undocumented and not necessary available in future versions. They were mostly added to give package builders ( for linux distro's) and crosscompilers a chance to evaluate possible option.

From Darwin (Mac OS X) i386

from i386 to powerpc

  • Cross binutils

First check if you already have the files powerpc-darwin-ld and powerpc-darwin-as:

 $ which powerpc-darwin-ld
 $ which powerpc-darwin-as

If you have these files skip the creation of the symlinks and go to the "Compile FPC" heading.

Actually, the "normal" binutils can be used, since they are universal. Therefore, simple symlinks are enough:

 $ sudo ln -s /usr/bin/as /usr/bin/powerpc-darwin-as
 $ sudo ln -s /usr/bin/ld /usr/bin/powerpc-darwin-ld

The symlinks can be in any other directory, as long as it is in your $PATH (for example /sw/bin when installing through fink).

  • Compile FPC:
 $ cd fpc/compiler
 $ make cycle CPU_TARGET=powerpc

This creates the powerpc compiler (fpc/compiler/ppcppc) and the units of the rtl.

In order to create powerpc binaries no actual crosscompiler is needed. The powerpc fpc and ppcppc run fine on IntelMacs using Rosetta.

More test and docs are needed for parallel installation of both and usage.

If there are missing units, check your config file, $HOME/.fpc.cfg or /etc/fpc.cfg or /sw/etc/fpc.cfg You may have to add something like or where ever your units are located.

-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/
-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
-Fu/usr/local/lib/fpc/lib/fpc/$fpcversion/units/$fpctarget/*

Reminder: Universal binaries are created from the individual (i386 and powerpc) binaries using lipo.

Cross compile FAQ

Por que cross-compilação?

Assim você pode desenvolver um programa para um OS/CPU e compilá-lo para outro OS/CPU sem reiniciar ou trocar de computador.

Why Linux to Windows and not the other way around?

The main reason for this is that generating unix binaries on a foreign platform (another unix or even Linux distro included) is more complicated. Static linking is already complicated, let alone shared.

You would need the used libraries from the target platforms (gtk, glib,libc etc), and a lot of additional configuring for ld. (library paths, dynlinker path, etc.)

This has been partially done (for the static case), but it is hard since it needs manual postediting of linker files and linker commandline, and a deep understanding about what makes Unix binaries tick.

I want more information on building Freepascal. Where is it?

This is a general FAQ in pdf format about how to build and configure FPC: http://www.stack.nl/~marcov/buildfaq.pdf.