[Lazarus] Cross-compiling Linux project to Windows from inside IDE
Graeme Geldenhuys
graeme at mastermaths.co.za
Mon Nov 9 13:22:29 CET 2009
Vincent Snijders wrote:
>>
>> 1) Manually created a cross-compile script for fpGUI Toolkit, because
>> Lazarus Packages don't seem to support different files for various
>> platforms. So I have two .lpk files for Lazarus. One for Linux and one
>> for Windows.
>
> What support do you expect? Almost all packages in the components dir are cross
> platform, take for example printers4lazarus package.
I knew after I posted the message that I would have to explain this one.
:-) Just solving this step would already reduce the cross-compiling
effort, but I don't have a solution yet.
Below is a partial layout of fpGUI project directory, to help explain my
reason for multiple .lpk files - one for each backend (platform).
/home/graemeg/programming/fpgui
.
|-lib
|---i386-linux
|---i386-win32
|---x86_64-linux
|-src
|---corelib
|-----gdi
|-----x11
|---gui
All sub-directories inside 'lib' are created by Lazarus. 'lib' is where
all compiler unit files end up. eg: *.ppu *.o etc..
The 'src' directory is the tricky one. Here I am not sure if Lazarus
Packages support what I need - or maybe I can change my code to
accommodate Lazaurs IDE. Not sure.
Inside the 'gdi' directory is the fpgui_toolkit.lpk file for Windows.
Inside the 'x11' directory is the fpgui_toolkit.lpk file for Linux &
FreeBSD. So now any fpGUI based application (windows or linux) refer to
'fpgui_toolkit.lpk' as a dependency package without problems. Inside the
'corelib' is all the common (platform independent) code, and then
backend specific code is either in 'x11' or 'gdi'. For example, I will
have a unit defined in 'corelib'. It's Interface section is common to
all platforms, but for the implementation section I will have a include
file only. The include file will be located in the backend specific
directories (x11 or gdi).
Also, each platform specific .lpk file will also include its platform
specific units. For example, under 'x11', I include some custom Xlib
header translation, XFT header translation and X11 NetManager
implementation files, which are obviously not related to Windows, so
only appear in the X11 supported platform package.
If I translate the above to FPC command line parameters (like I have in
a extrafpc.cfg file), I have this layout.
-----------------------
# searchpath for include files
-Ficorelib
#IFDEF X11
-Ficorelib/x11/
#ENDIF
#IFDEF GDI
-Ficorelib/gdi/
#ENDIF
# searchpath for units and other system dependent things
-Fu.
-Fucorelib/
#IFDEF X11
#WRITE Compiling X11 CoreLib
-Fucorelib/x11/
#ENDIF
#IFDEF GDI
#WRITE Compiling GDI CoreLib
-Fucorelib/gdi/
#ENDIF
-Fugui/
-Fugui/db/
# Unit output path
-FU../lib/$fpctarget/
-----------------------
So how can Lazarus Packages support my requirements? Alternatively, is
there another way I can restructure my code - but I can't really see how.
>> 3) Environment Options: Change Compiler path and FPC Source Path.
>
> Why? Just choose fpc as compiler and let fpc call the ppcXXX compiler based on the
> -P parameter.
I have had problems with 'fpc' on my system, so for some reason I only
have ppcXXX files. I'll try and recompile my FPC again to see if I can
resolve this issue.
The reason for the Source Path change is because I use FPC 2.2.5 to
compile FPC 2.3.1 (64bit). So for 64bit (linux) work, I mainly use FPC
2.3.1 code. And because FPC 64bit executable cannot create a
cross-compiled FPC 32bit executable, I keep using the 2.2.5 for 32bit
development. So I used FPC 2.2.5 (32bit linux) to cross-compile a FPC
2.2.5 windows 32bit compiler.
I did post a question in the fpc-users mailing list as to why 64bit FPC
cannot create a 32bit FPC, but vice-versa is possible.
>> 4) In my Project Compiler Options dialog, go to Code tab and change
>> target platform and CPU to 'Windows 32' and 'i386'. Remember, by current
>> setup is Linux with 64bit FPC.
>
> These steps are indeed necessary.
I suppose if the IDE supported Build Modes like MSEide, this would have
made things much simpler. Simply select Run and then any of the build
modes you setup in the menu.
>> 6) If fpGUI code changed, manually run the cross-compile scrip.
>
> Why don't you let the IDE recompile the package?
As I explained above. It's a bit more complex, using different units per
platform and using different include paths per platform. I'll take a
look now at the printers4lazarus packages you mentioned. Maybe that will
give me some hints on how I could solve issue (1).
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/
More information about the Lazarus
mailing list