mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-24 02:26:26 +02:00
100 lines
4.1 KiB
Plaintext
100 lines
4.1 KiB
Plaintext
Hints to cross compile win32 binaries under linux
|
|
=================================================
|
|
|
|
|
|
Thanks to Vincent Snijders for the hints.
|
|
|
|
|
|
1. Download the GNU binutils - Binary Utility Development Utilities.
|
|
Many packages (RPM, DEB, TGZ) are outdated or not compatible. So, here is a link
|
|
that worked for me:
|
|
http://jrfonseca.dyndns.org/projects/gnu-win32/documentation/cross/
|
|
Download all files into a directory of your choice. The directory should have
|
|
at least 250mb space which will be needed for building.
|
|
There is a small bug in xmingw32.mak. Open the file, search for '#$(GCC' and
|
|
remove the '#' character to uncomment.
|
|
Then do as root 'make -f xmingw.mak'. This will download the binutils, the gcc
|
|
and the mingw32 files and will compile them. Then it installs them under
|
|
/usr/local/xmingw32/. You can change the target directory and compile as
|
|
normal user by changing the script.
|
|
|
|
|
|
2. The cross tools needed by FPC
|
|
FPC needs four files: asw, ldw, windres and dltool. You can
|
|
- link the following files:
|
|
|
|
[]$ ln -s /usr/local/xmingw32/bin/mingw32-as /usr/bin/asw
|
|
[]$ ln -s /usr/local/xmingw32/bin/mingw32-ld /usr/bin/ldw
|
|
[]$ ln -s /usr/local/xmingw32/bin/mingw32-windres /usr/bin/windres
|
|
[]$ ln -s /usr/local/xmingw32/bin/mingw32-dlltool /usr/bin/dlltool
|
|
|
|
You can link them as normal user somewhere in your home. But then you have to
|
|
add this directory to your PATH or add -FD/your/directory everytime you cross
|
|
compile with fpc.
|
|
|
|
|
|
2. Download or compile the win32 units (ppw,ow files for rtl, fcl). These files
|
|
must be compatible (depending on the compiler probably 1.0.10 as of now).
|
|
Install them next to the linux units in /usr/lib/fpc/1.0.x/units.
|
|
See (a) or (b).
|
|
|
|
|
|
(a) Download the win32 units: Currently you can download the win32 snapshots at
|
|
ftp://ftp.freepascal.org/pub/fpc/snapshot/v10/win32-i386/
|
|
and unzip them into $UsrLib/fpc/$FPCVersion/units/win32. $UsrLib is the place
|
|
where fpc is installed. Probably /usr/lib/ or /usr/local/lib.
|
|
|
|
|
|
(b) Compile the win32 units:
|
|
Download the fpc sources, compile them and install them. This makes sure your
|
|
compiler is compatible to the source. The same source directory can be used for
|
|
win32, because the output files have different names (.ppu <> .ppw, .o <> .ow).
|
|
Then compile the win32 units (.ppw, .pw):
|
|
|
|
[]$ make clean OS_TARGET=win32
|
|
[]$ make -C compiler cycle OS_TARGET=win32
|
|
[]$ make fcl packages OS_TARGET=win32
|
|
|
|
Install the units:
|
|
|
|
[]$ make -C rtl install OS_TARGET=win32
|
|
[]$ make -C fcl install OS_TARGET=win32
|
|
[]$ make -C packages install OS_TARGET=win32
|
|
|
|
This will create the correct directory structure, but probably in the wrong
|
|
directory. Move the /usr/local/lib/fpc/<version>/i386-win32/units directory to
|
|
your fpc install directory. For example if your linux units (e.g. classes.ppu)
|
|
is located in /usr/lib/fpc/1.0.10/units/linux/ then do
|
|
[]$ rm -rf /usr/lib/fpc/<version>/units/win32
|
|
[]$ mv /usr/local/lib/fpc/<version>/cross/i386-win32/units /usr/lib/fpc/<version>/units/win32
|
|
|
|
|
|
3. Making /etc/fpc.cfg target independent:
|
|
Make sure that your /etc/fpc.cfg contains target independent paths:
|
|
-Fu/usr/lib/fpc/$version/units/$target
|
|
-Fu/usr/lib/fpc/$version/units/$target/*
|
|
-Fu/usr/lib/fpc/$version/units/$target/rtl
|
|
You should now be able to cross compile simple pascal programs with
|
|
'ppc386 -Twin32 pascalfile.pas'
|
|
Or if you did not link the four files (asw, ldw, ...) to /usr/bin:
|
|
'ppc386 -FD/your/directory -Twin32 pascalfile.pas'
|
|
|
|
|
|
4. Cross compiling the LCL
|
|
4.1 Command line: cd lazarus/lcl; make OS_TARGET=win32
|
|
4.2 In the IDE: Set LCL to Clean+Build, set LCL interface to win32 and
|
|
set 'Target OS' to win32. Then 'build lazarus'. The win32 interface is not
|
|
complete enough for the IDE, but many of the components already work.
|
|
|
|
|
|
5. Cross compiling a project
|
|
Set in Run->Compiler Options->Code the Target OS to 'win32' and in Paths the
|
|
'LCL Widget Type' to win32. That's all. The next time you build, you will
|
|
create a win32 executable.
|
|
The IDE will rescan for win32 units, so that 'Find declaration' and code
|
|
completion features will now work with the win32 rtl instead of the linux rtl.
|
|
When you open another project or reopen this project the IDE will automatically
|
|
switch.
|
|
|
|
|