Suppose you installed Lazarus 1.8 on Linux Mint 18.3 as described before and want to build Windows binaries (well we don’t like Windows, but the users do 🙂 ). I’ve found the useful piece of information about crosscompiling here and started to adopt it to my 32-bit Linux system.
The first step is to build and install the crosscompiler. For the demonstration purposes I decided to build Win32 crosscompiler (the Win64 case should not be much different).
Lazarus 1.8 uses FPC version 3.0.4, so to perform the first step open up Terminal and execute following commands:
# Navigate to the fpc source folder.
# Compile the cross-compiler.
sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
# Install the cross-compiler.
sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
# Link the cross-compiler and place the link where Lazarus can see it.
sudo ln -sf /usr/lib/fpc/3.0.4/ppcross386 /usr/bin/ppcross386
Now let us open Lazarus and create a simple GUI project. I dropped a button on the form and written OnClick handler:
procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('Hello World!'); end;
I created subfolder /Projects/Lazarus/HelloWorldGUI in my home folder and saved the project under the name HelloW. You can build and run the project and see it works.
Now time to configure the project for Win32 crosscompiling. Open Project Options dialog (Ctrl-Shift-F11). You should see this:
Check Build Modes checkbox:
and click the ellipsis button; a new dialog appears:
Click plus button to create a new build mode, and name it Win32:
Now we should tell Lazarus to compile Win32 code for this build mode. Select Config and Target on the left panel and select Win32 as target OS:
Now you can build the project. I simply clicked green Run button and obtained the warning window:
Well I guess one can’t expect to debug Win32 binary on Linux. Still the work was done, and I’ve found HelloW.exe file in the project folder. To be sure I’ve copied the file on 64-bit Windows 10 system, and It Works!