How to Cross Compile with Lazarus [Video Guide]
Channel: needadnan
Date: 2020-05-12

Visit **LazPlanet** to discover how you can use Lazarus in many interesting ways: https://lazplanet.blogspot.com

To Download Free Pascal: https://freepascal.org/download.html

In this video guide we check out the amazing ways to cross compile between Windows 32bit and 64bit systems. Also we look into how we can use our Linux installation to compile to Windows! I didn't know it was possible until making this video!

The cool thing about it is that you can compile Windows versions without having to run Windows. There are support for other platforms as well. Be sure to check the wiki: https://wiki.lazarus.freepascal.org/Cross_compiling

Do you want to create executables for another OS that you are not currently in? Then this video is for you. Cross compiling let's you create executables without having a full install or virtual machine version of an OS just to compile to it. It's easy to configure and maintain. Definitely a must see for any dedicated Free Pascal developer.

This is useful if you want to streamline your dev process or just want to experiment with this amazing stuff!

There is a text version of this guide here: https://lazplanet.blogspot.com/2020/05/cross-compile-on-lazarus.html


Stuff to copy-paste
====================

# From Win64 to Win32

Tools - Options - Environment - Compiler executable to "$(LazarusDir)fpc\$(FPCVer)\bin\$(TargetCPU)-$(TargetOS)\fpc.exe"


# From Win32 to Win64

Tools - Options - Environment - Compiler executable to "C:\lazarus\fpc\$(FPCVer)\bin\i386-Win32\fpc.exe"


# Command to install on Linux

You can use the code below on Linux operating systems to install cross compiler for both Win32 and Win64:

```
#!/bin/sh
# To use the fpc version number later
# It has the version number, e.g. 3.0.4
export FPCVER=`fpc -iV`
# Navigate to the fpc source folder.
# One of them will fail, but this is normal. If it changes into a directory, you're fine.
cd /usr/lib/fpc/src/ || cd /usr/share/fpcsrc/$FPCVER

# Compile the cross-compiler for win32.
sudo make clean all OS_TARGET=win32 CPU_TARGET=i386
# It could take a minute or two, depending on your hardware

# Install the cross-compiler.
sudo make crossinstall OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=/usr
# You should see messages like: Installation package fpc-all for target i386-win32 succeeded

# Link the cross-compiler and place the link where Lazarus can see it.
sudo ln -sf /usr/lib/fpc/$FPCVER/ppcross386 /usr/bin/ppcross386

# You can do the same using Windows 64 bit as target.
export FPCVER=`fpc -iV`
cd /usr/lib/fpc/src/ || cd /usr/share/fpcsrc/$FPCVER
sudo make clean all OS_TARGET=win64 CPU_TARGET=x86_64
sudo make crossinstall OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=/usr
sudo ln -sf /usr/lib/fpc/$FPCVER/ppcrossx64 /usr/bin/ppcrossx64
```

* You may need to provide your superuser password.

Besides copy-pasting each line, you can save this as a `.sh` file and run `sh /path/to/the/file.sh` to run them automatically.

* I have tested this with Windows 7 and Ubuntu 20.04 LTS. This should work with newer Windows and other Linux distros, such as, Debian, Arch Linux, Fedora, Void Linux. Please let me know if you face any issues.


AUDIO:
- Ambisax - RRound
- Palmtrees - INGS
- Just Cool - Wowa & eckskwisit
- Naya - HaTom
All from unminus.com under CC0 license.