PDA

View Full Version : Cross-Compelation with Lazarus



WILL
10-05-2006, 08:26 AM
I'm running Lazarus off of Windows XP and I'd like to make my cross-platform compatable project available on Linux and Mac OS X.

This is the first time that I am doing this and want to know what considerations --as a brief rundown-- do I need to take while doing this under the latest Lazarus.

Also, anyone interested in testing to see that I got it working? (it's my NS2 project that I have posted in the 'My Projects' forum)

marmin
27-05-2006, 04:55 AM
- be careful with threads (in lazarus 9.14 the win32 code with tthread won't work on Linux)
- remove everything that is windows (obvious but tricky as some things can be hidden in the code).

And, of course, installing Lazarus on a Linux box is (compared to win32 install).. pain. But, if it's finally running it's stable.

WILL
27-05-2006, 05:22 AM
Ok well those two don't seem to be a factor at this point, but good thing to note. :)

There is however some issues reguarding this line of code which in Windows prevents the console window from poping up.
{$APPTYPE GUI} // FreePascal/Lazarus
Alternative?

AND it gives me an error saying:

NightStalker2.lpr(1,1) Fatal: Can't find unit System

Here is my main program code's uses:
uses
SysUtils,
Math,

sdl,
sdlutils,
sdl_mixer,

// These are just my own units!
NS2ConstantsUnit,
NS2ObjectUnit,
NS2FunctionsUnit,
InputUnit,
FontUnit,
GraphicsUnit;

dmantione
27-05-2006, 06:27 AM
Cross-compiling from win32 to Linux is reasonably hard because you need the shared libraries you link to on your Windows system. Lazarus is not shipped with a Linux rtl, you must compile it yourself.

{$APPTYPE GUI} is not necessary under Linux. You will get a warning if you try it, you either ignore the warning or {$fdef win32} it.

WILL
27-05-2006, 06:35 AM
Ah! I see.... well thats something that would perhaps go on a requested features list no? :)

So what is probably the easiest way to plug in the Linux RTL so that I may cross-compile?


Oh and after setting this up at the top of my program's code I doubt I'll have more issues of that nature. ;)

{$IFDEF Win32}
{$IFDEF FPC}
{$APPTYPE GUI} // FreePascal/Lazarus
{$ELSE}
{$APPTYPE CONSOLE} // Delphi
{$ENDIF}
{$ENDIF}

dmantione
27-05-2006, 07:49 AM
Ah! I see.... well thats something that would perhaps go on a requested features list no? :)

Perhaps with the internal ]
So what is probably the easiest way to plug in the Linux RTL so that I may cross-compile?
[/quote]

Install the runtime library source code, use the makefile, and make the compiler point to the unit by the appriopriate command line options. There also a few threads about this on the Free Pascal forums, in case you need some help.



Oh and after setting this up at the top of my program's code I doubt I'll have more issues of that nature. ;)


I don't think so. Well, in 2.2 there will be Win64 and Windows define for the new win64 platform.

WILL
27-05-2006, 08:41 AM
Ah! I see.... well thats something that would perhaps go on a requested features list no? :)

Perhaps with the internal ]

Ah, but the internal linker is soon to replace the GNU one, no? :thumbup:


Install the runtime library source code, use the makefile, and make the compiler point to the unit by the appriopriate command line options. There also a few threads about this on the Free Pascal forums, in case you need some help.

Ok, I'll give this a go and let you know how I did. ;)


[quote="WILL"]
Oh and after setting this up at the top of my program's code I doubt I'll have more issues of that nature. ;)


I don't think so. Well, in 2.2 there will be Win64 and Windows define for the new win64 platform.

What will be the IFDEFs for those? Win64 and Windows?

There obviously won't be one for 'Delphi', for obvious reasons. :P

dmantione
27-05-2006, 08:50 AM
Ah, but the internal ]

I hope so!

[quote="WILL"]
What will be the IFDEFs for those? Win64 and Windows?
There obviously won't be one for 'Delphi', for obvious reasons. :P


Yes, the defines will be called "win64" and "windows". It might be a good idea to write:


{$ifdef win32}
{$define windows}
{$endif}


... at top of your code and use {$ifdef windows} instead in the rest of your code, so it will already be compatible with win64.