Recent

Author Topic: Cross Compiling  (Read 725 times)

J-G

  • Hero Member
  • *****
  • Posts: 770
Cross Compiling
« on: May 19, 2022, 03:39:22 pm »
Having updated to Laz 2.2.0 ( I see 2.2.2 is now available!!) from Laz 1.6, simply to take advantage of resizing 'Hints', I would also not like to compile for use on Linux, Mac and posibly Android.

Now, I may well be naïve and completely mis-understand the distinction between Cross-Platform & Cross-Compling but I would appreciate guidance.

I'm using Windows 7 64 bit, I can create 64bit & 32bit programs simply by changing the 'Target CPU Family' in the [Project Options] but If I select (say) MacOS as the 'Target OS' leaving the CPU family as [Default] - I get a warning that the current FPC has no config file.

I can understand that I would need to install some 'add-on' and I would expect this to be a 'Cross-Compiler' but I haven't been able to find such on Laz or FPC sites. It's possible that I've been looking for the wrong thing or even in the wrong place but with so many 'Options' I'm simply at a loss as to know what I should be looking for.

A similar situation exists of course for Linux & Android.

Can someone enlighten me please?

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 9733
Re: Cross Compiling
« Reply #1 on: May 19, 2022, 04:03:48 pm »
For me, "cross-compilation" is largely overestimated. Even if it creates a valid binary for the destination platform you cannot necessarily run and test the application on that platform. And believe me, tiny changes in code working on your normal platform can have unwanted effects on another platform.

Therefore, rather than cross-compiling I have set up virtual machines and installed the other OSes on them. On these VMs I installed Lazarus again. This way I can compile and test the application like on my normal platform.

The VMs are always set up so that there is access to the code base on the normal platform.

I did use cross-compilation, so far, for rare activities with WinCE and Arduino. In this case, I used FPCUpDeluxe to install Lazarus and prepare it for cross-compilation since FPCUpDeluxe can get the required libraries very easily (https://wiki.freepascal.org/fpcupdeluxe#Cross-compiling).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Zvoni

  • Hero Member
  • *****
  • Posts: 1223
Re: Cross Compiling
« Reply #2 on: May 19, 2022, 04:10:36 pm »
It starts with reading the Wiki
https://wiki.freepascal.org/Cross_compiling

EDIT: But i agree with wp:
Setup VM's (e.g VirtualBox) with the Target-OS/Bitness, install Lazarus/FPC there.
Done correctly, you don't have to move your sourcecode around

Beware: AFAIK, there are legal issues when running MacOS as a guest in a VM
« Last Edit: May 19, 2022, 04:13:16 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

J-G

  • Hero Member
  • *****
  • Posts: 770
Re: Cross Compiling
« Reply #3 on: May 19, 2022, 04:51:50 pm »
Thanks both,

You've essentiall confirmed what I had surmised  -  It ain't easy  -  :D

In fact there is no way that want MacOS anywhere near my PCs ;D  Linux might be another matter but I suspect that if I did go down that route it would be on a separate PC so could install Laz for Linux  -  and I'm sure that would throw up even more complications which would be totally outside my comfort zone  %)

I'll leave well alone!

This does beg the question about the [Project Options] [Config and Target] [Target Platform] drop-down lists though - why - on a Win 64bit installation - is it posible to select 'Android', 'BeOS',  'Java', 'Linux' . . . ?   

Maybe these questions would be answered if I read the [Cross-compiling] Wiki  ;D
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1983
  • Former Delphi 1-7, 10.2 user
Re: Cross Compiling
« Reply #4 on: May 20, 2022, 05:41:35 am »
For me, "cross-compilation" is largely overestimated. Even if it creates a valid binary for the destination platform you cannot necessarily run and test the application on that platform.

All my Windows compilation is done on macOS. I've not run into any issues with the produced executables failing in Windows. I do it because it is very convenient (and needed no additional tools other than the normal FPC + Lazarus). FreeBSD and Linux compilation is done in their own VMs with a full FPC + Lazarus installation from source.

Quote
And believe me, tiny changes in code working on your normal platform can have unwanted effects on another platform.

I do always test the produced executables in multiple Windows VMs (2000, XP, XP-64, 10-64, 11-64) running in Parallels on macOS.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.4
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.4

PascalDragon

  • Hero Member
  • *****
  • Posts: 4119
  • Compiler Developer
Re: Cross Compiling
« Reply #5 on: May 20, 2022, 04:06:13 pm »
For me, "cross-compilation" is largely overestimated. Even if it creates a valid binary for the destination platform you cannot necessarily run and test the application on that platform. And believe me, tiny changes in code working on your normal platform can have unwanted effects on another platform.

Compiling from a single platform does not necessarily mean that you only test on a single platform (at least it wouldn't for me).

I can understand that I would need to install some 'add-on' and I would expect this to be a 'Cross-Compiler' but I haven't been able to find such on Laz or FPC sites. It's possible that I've been looking for the wrong thing or even in the wrong place but with so many 'Options' I'm simply at a loss as to know what I should be looking for.

A similar situation exists of course for Linux & Android.

Can someone enlighten me please?

We don't provide a cross compiler by default from Windows to macOS or Linux (I think we do provide the Android one however), you'd need to build that yourself. However with recent macOS versions there might be the problem that cross compiling to macOS is no longer possible, because no suitable build utilities exist for non-Apple platforms (I can neither confirm nor deny this however, so take this with a grain of salt). In any case you also need the libraries from the target platform, because unlike Windows compiling for Linux or macOS requires the libraries to be present during linking.
So unless you want to invest the time to set this up (once) your best choice is to use a virtual machine or in case of Linux you can also use Windows Subsystem for Linux.

J-G

  • Hero Member
  • *****
  • Posts: 770
Re: Cross Compiling
« Reply #6 on: May 20, 2022, 10:40:08 pm »
Thanks for the feed-back PascalDragon.

I'd pretty much decided that the time & effort involved was beyond my wit :)

Taking a 'left-field' approach - - - -  and I'm not at all sure that this is even possible  - - - -   one of the major marketing points of Lazarus is (and I quote) "Lazarus and Free Pascal strives for write once compile anywhere"  - - - -  so, If I were to make my source code (along with the various .pas, .lfm, .lpr  - etc. files)  available would there be someone willing and able to simply load and compile for MacOS ?   Or is my naïvety showing yet again ?

The project I have in mind is less than 800 lines of code.

« Last Edit: May 20, 2022, 10:42:02 pm by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1983
  • Former Delphi 1-7, 10.2 user
Re: Cross Compiling
« Reply #7 on: May 21, 2022, 02:35:03 am »
If I were to make my source code (along with the various .pas, .lfm, .lpr  - etc. files)  available would there be someone willing and able to simply load and compile for MacOS ? 

Sure. I can compile for macOS on Intel and Apple Silicon and create a universal binary if required. PM me.
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 x86_64 Xcode 13.4
Lazarus 2.3, FPC 3.3.1 macOS 12.3.1 aarch64 Xcode 13.4

J-G

  • Hero Member
  • *****
  • Posts: 770
Re: Cross Compiling
« Reply #8 on: May 21, 2022, 10:45:13 am »
Sure. I can compile for macOS on Intel and Apple Silicon and create a universal binary if required. PM me.
Thanks Trev  -  PM sent.
« Last Edit: May 22, 2022, 10:09:21 am by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018