Cross Compiling lazarus / 21-General ---------------------------------------------------------------------- J-G · 2022-05-19 13:39 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? ---------------------------------------------------------------------- wp · 2022-05-19 14:03 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). ---------------------------------------------------------------------- Zvoni · 2022-05-19 14:10 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 ---------------------------------------------------------------------- J-G · 2022-05-19 14:51 Thanks both, You've essentiall confirmed what I had surmised  -  It ain't easy  -  In fact there is no way that want MacOS anywhere near my PCs   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 ---------------------------------------------------------------------- trev · 2022-05-20 03:41 Quote from: wp on May 19, 2022, 04:03:48 pmFor 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. ---------------------------------------------------------------------- PascalDragon · 2022-05-20 14:06 Quote from: wp on May 19, 2022, 04:03:48 pmFor 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). Quote from: J-G on May 19, 2022, 03:39:22 pmI 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 · 2022-05-20 20:40 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. ---------------------------------------------------------------------- trev · 2022-05-21 00:35 Quote from: J-G on May 20, 2022, 10:40:08 pmIf 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. ---------------------------------------------------------------------- J-G · 2022-05-21 08:45 Quote from: trev on May 21, 2022, 02:35:03 amSure. I can compile for macOS on Intel and Apple Silicon and create a universal binary if required. PM me.Thanks Trev  -  PM sent.