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 http://packages.debian.org or http://packages.ubuntu.com . 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.


ld-linux.so.2     libogg.so.0  libsndfile.so.1
libaudio.so.2     libpcre.so.3  libsqlite3.so.0
libc.so (copy and rename libc.so.6)     libphonon.so.4  libstdc++.so.6
libc.so.6     libpng12.so.0  libuuid.so.1
libdbus-1.so.3     libpthread.so.0  libvorbisenc.so.2
libdl.so.2     libpulsecommon-0.9.22.so  libvorbis.so.0
libexpat.so.1     libpulse-mainloop-glib.so.0  libwrap.so.0
libFLAC.so.8     libpulse.so.0  libX11.so
libfontconfig.so.1   libQt4Pas.so (copy and rename libQt4Pas.so.5)  libXau.so.6
libfreetype.so.6     libQtCore.so.4  libxcb-atom.so.1
libgcc_s.so.1     libQtDBus.so.4  libxcb.so.1
libglib-2.0.so.0     libQtGui.so.4  libXdmcp.so.6
libgobject-2.0.so.0  libQtNetwork.so.4  libXext.so.6
libgthread-2.0.so.0  libQtWebKit.so.4  libXrender.so.1
libICE.so.6     libQtXml.so.4  libXt.so.6
libm.so.6     librt.so.1  libz.so.1
libnsl.so.1     libSM.so.6


And in the end you should get something working


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



No comments: