Wednesday, March 23, 2011

Cross compiling from Windows to Linux (QT Interface)

Again I was if I can make a Linux executables without switching back into my Linux Mint 10 or using virtual machine. This time I decided to play around with QT interface. First I needed to rebuild LCL for QT Interface and set project to use QT widget set and Linux i386 architecture.
Since I got my Linux partition working on Windows using awesome Ext2fsd tool that lets you mount EXT2/EXT3 partitions on Windows systems I just needed to set a path to Linux lib folders /lib/ and /usr/lib/ in Lazarus project path
field. But if you don't have Linux on your machine you may come to really time consuming way to build Linux executables.

Step by step

1. Download the CodeTyphon and and using "setup.bat" or CodeTyphon Center choose
the  Remove and Build ALL (FPC + Lazarus). This should setup the brand new IDE for your development.
2. Using CodeTyphon Center build a cross-compiler. Select from menu
Cross-build->Free Pascal 32bits->FPC32 build cross element i386-linux
After completing this step now you need to build Lazarus cross element.
Select from menu Cross-build->Lazarus32 build cross element i386-linux
3. If everything went smooth now you should have  a cross-compiler. Start the Lazarus IDE and
make a simple application or open some sample from Lazarus examples folder.

Yeah very random test app... :)

Now build the LCL with QT widget set. To do this in Lazarus menu select Tools->Configure "Build Lazarus"... . In a opened window select:
Profile to Build: Build LCL
LCL Widget Type: qt
Target OS: Linux
Target CPU: i386
[x] With Packages.
Leave all other options default and press Build button.

4. From the Lazarus IDE menu select Project->Project Options... or just press CTRL+Shift+F11
In the Build modes options select macros LCLWidgetType to qt
I was using Lazarus 0.9.31. The macros might not be available in an older versions.
You may need to find  a LCL Widget Type option in another options page...

At the same window, in a compiler options in a Code generation page you need to set the Target Platform. Simple from drop-down menu select Target OS : Linux and and Target CPU family: i386.

5. Now you will need to have a lots of Linux libraries to link  an executable. Here is the whole list that may need to download from or . Or maybe a friend with Linux can send it to you. After downloading all those libs create the folder "LinuxLibs" or etc. and add it to project paths. Here are all the libs you will need from /lib/ and /usr/lib/ folders. (copy and rename (copy and rename

And in the end you should get something working

Same app running on Linux Mint 10.
Goodluck with having fun :)

No comments: