Recent

Author Topic: Another question about cross-compiling  (Read 1921 times)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #30 on: October 13, 2024, 10:28:44 pm »
As mentioned in previous message.
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #31 on: October 13, 2024, 10:44:08 pm »
Quote
Just to reiterate, I'm after a single "Compiler Executable" which will call either the macOS "/Applications/Lazarus_trunk/fpc/bin/x86_64-darwin/fpc.sh" command, or the "/usr/local/bin/ppcrossx64" command for Windows.
It should be the former, which script will point to the actual fpc (front-end) compiler.

Selecting the target processor and os in the project options then should automatically invoke the ppccrossx86 cross-compiler.

I tried that and the build is failing on...
Code: Text  [Select][+][-]
  1. Verbose: Compiling fcllaz.pas
  2. Fatal: Cannot find system used by fcllaz of package FCL.
  3.  

BTW: perhaps it is me but I could have sworn that you mentioned windows on arm (and therefor also assume mac on arm). Neither of which seems to be true according to what I am able to see now.

No, the macOS and Windows are both ARM systems running on the same Mac Mini M1! The mention of "x86_64-darwin" came about because that was the resultant path of the cross-platform compiler which was built. I didn't choose it!

There is no macos(all) unit for targets that are not macos.
Reason is simple: the macosall unit binds itself to the underlying required frameworks and these do not exist on other platforms besides macos.

No! If you look at the code I posted, the only place that MacOSAll is referenced is in the file "camidimac.pas" which is de-coupled from the rest of the app by a combination of interfaces and compiler directives 😉

While on the subject of sharing, could you share the fpc.cfg used by the cross-compiler as well ? That should include the missing parts that need to be added top the fpc.cfg that was shared in your post.

Let me see if I can track it down...

UPDATE: The cross-compiler "ppcrossx64', located in my "/usr/local/bin" and used successfully for Windows builds, is an alias for "/usr/local/lib/fpc/3.2.2/ppcrossx64". I've no idea which "fpc.cfg" it uses...
« Last Edit: October 13, 2024, 10:56:44 pm by carl_caulkett »
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: Another question about cross-compiling
« Reply #32 on: October 13, 2024, 11:50:46 pm »
Ok, if you do not mind then let's do a reset for a moment.

First the positive. After some tinkering I was able to cross-build your (Experimental) project from linux x86_64 to win64 x86_64.

The tinkering consisted of:
  • removing -VM11.0 from the project options. Every (cross)build done prior to that (thus including that option) requires a clean up and rebuild of the project otherwise the compiler will fail (even though the option was already removed and doing a rebuild, thus the cleanup is necessary in that case).
  • I had to add at least something to the windows midi unit (unit name interface and implementation parts)
  • for some reason the spineditex has some properties removed in Lazarus 3.4 (I had to remove them manually from the lfm file, but Lazarus also offers to do it for you)
  • something else that I forgot while writing this (perhaps it comes back to me later)  :-[

The bad news: sorry to say but your current setup of FPC and Lazarus looks like a mess. someone knowing all the ins and outs would probably able to solve it in a jiffy but doing this with this ancient form of communication is painful.

Therefor I would probably suggest to re-install both lazarus+fpc combo and the windows cross-compiler.

I've done so myself to build your project with a standalone Lazarus+FPC and cross-compiler combination that was setup with FPCUpdeluxe in under 10 minutes.

If the prerequisites are in place then it takes the following steps:

  • somewhere where you want to, I created the following directories:
      - bin/fpcup
      - bin/lazarus/3.4
  • downloaded fpcupdeluxe 2.4.0.e (your setup most probably requires the one named
    fpcupdeluxe-aarch64-darwin-cocoa.zip) in the bin/fpcup directory
  • make the fpcupdeluxe file executable (chmod u+x)
  • run FPCUpdeluxe, then:
  • set the install directory to bin/lazarus/3.4
  • from the left listbox select  FPC 3.2.2
  • from the  right listbox select Lazarus 3.4
  • press the install/update FPC+Lazarus button
  • put on kettle to boil some water
  • when the install is finished:
  • press the tab cross
  • select from left X86_64
  • select from right windows
  • press button "install compiler"
  • poor hot water in cup and get a teabag in there as well
  • depending on your taste remove teabag and get back to PC screen
  • close FPCUpDeluxe when the cross compiler build/installation finished
  • start freshly installed lazarus
  • load your project, take into account the changes that I had to make and as mentioned earlier
  • in project options, select target win64 and cpu x86_64,  and... (ah I remembered the thing I forgot ->) remove the build mac package options (perhaps they even disappear automatically when changing target to windows, I dunno)
  • save your project (to make sure all changes are saved)
  • build your project
  • sip tea

In the hope it is useful.

PS: a cross compiler is nothing more than a ppc backend and the units compiled for a specific target. a ppc backend is only required when the cpu differs from that of your own. Thus there is a ppc for arm, x86, i386, ppc (powerpc), m68k, etc etc. Therefor I choose to use the win64 x86_64 cross compiler because that is the cross-compiler that you seem to be using (ppccrossx86). The cross part in the name is to indicate that it is the cross-compiler and without the cross part in its name it indicates a native compiler. fwiw, for windows arm the cross compiler selection for FPCUpDeluxe should be aarch64 / win64 (but be aware that this requires clang)

PPS: in order to not have to remove and add options for a specific target in your project options the Lazarus IDE offers something called build-modes that can be used to use different project options for every build mode that is created. In order to cross-compile to another target it is then possible to change/select a specific build-mode from a combobox. The project options will then be changed (automatically and) accordingly.

PPPS: for the experimental project I noticed the space in the name of the directory. Dunno if that was for testing purpose or otherwise but please be advised that using a space for a project directory is able to cause issues. Most compiler tools (such as the FPC compiler, the linker and assembler are not capable to process spaces correctly and as a result fail).
« Last Edit: October 14, 2024, 01:02:20 am by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #33 on: October 14, 2024, 01:03:18 am »
Thanks for doing this TRon!

My current setup was created using "fpcupdeluxe" v2.4.0e, and was done by selecting 3.3.1 for FPC and 3.99 for Lazarus. I'd like to keep with these two versions if possible. I'm curious as to how it's a mess, given that I used similar steps to the ones that you outline... Maybe things are just done different(ly) in macOS 😉

What are "the prerequisites that need to be in place"? Does this refer to a base FPC/Lazarus installation on which your steps are built upon? Or do you just mean a working OS with a folder called "bin" that's in the OS search path?

It's also not clear from your "fpcupdeluxe" instructions if they will leave me with a Lazarus which runs in macOS but which is able to cross-compile to Windows on demand.

Another point is that the "-WM11.0" in the Project Options is to ensure that the resultant macOS executable respond to the macOS theme, dark or light. 

UPDATE: Okay I've been looking more closely at your instructions, and given that I'm quite happy with my current 3.3.1 + 3.99 macOS combo. it seems that I only really need to consider the steps from "press the tab cross" onwards, since they seem to deal with the addition of the cross-compiler components.

I'm guessing that I need to repeat the...
Code: Text  [Select][+][-]
  1. * select from left X86_64
  2. * select from right windows
  3. * press button "install compiler"
  4.  
...steps for as many different extra target platforms as I need. These would be Mac (Intel), Linux and Windows.

Does that sound like a reasonable basis for my next steps?

Thanks again!
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #34 on: October 14, 2024, 01:12:20 am »
Oh! My beverage of choice is currently a mug of Machu Picchu ground coffee, to start the day followed by the odd Guarana capsule washed down with good old H2O 😉
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #35 on: October 14, 2024, 01:16:21 am »
PPPS: for the experimental project I noticed the space in the name of the directory. Dunno if that was for testing purpose or otherwise but please be advised that using a space for a project directory is able to cause issues. Most compiler tools (such as the FPC compiler, the linker and assembler are not capable to process spaces correctly and as a result fail).

No spaces here...
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: Another question about cross-compiling
« Reply #36 on: October 14, 2024, 01:45:57 am »
Thanks for doing this TRon!
You are more than welcome carl.

As long as you have/show incentive then I am more than happy to share my knowledge (how minimal it might perhaps be) and please do share what you've learned (if any). There are not that many mac users around so any help is welcome in that regards.

Quote
My current setup was created using "fpcupdeluxe" v2.4.0e, and was done by selecting 3.3.1 for FPC and 3.99 for Lazarus. I'd like to keep with these two versions if possible. I'm curious as to how it's a mess, given that I used similar steps to the ones that you outline... Maybe things are just done different(ly) in macOS 😉
It is guessing on my part but based on the evidence so far I believe that you first installed Lazarus+FPC combination in some (specified) directory and later on installed the cross-compiler but doing so system-wide (that or you have another system wide installation done on a previous occasion,and perhaps even removed later but some remnants were left).

There is always the possibility that things are done differently on/for macos but Don (the FPCUpDeluxe maintainer) is pretty consistent when it comes to how FPCUpDeluxe does it setups.


Quote
What are "the prerequisites that need to be in place"?
That depends on the platform that you are using. For as far as they are known they are listed here for all platforms. F.e. for Linux I have to install some packages because Lazarus relies on them but also because some basic development tools are required.

Quote
Does this refer to a base FPC/Lazarus installation on which your steps are built upon?
No  :)

FPCUpdeluxe does not require anything else than mentioned. No other Free Pascal compiler or Lazarus is needed. Even stronger I would personally recommend removing at least any system wide installed FPC and/or Lazarus prior to using FPCUpDeluxe as the program itself keeps it very neat and clean.

FPCUpDeluxe tries to download all other requirements automatically for you and install them to designated directories in your installation path.

Do keep in mind that FPCUpdeluxe allows a user to set some customization options as well as allow you to add custom parameters to the build-process thus you can influence some things (but that would then be your own doing/responsibility).

In case FPCUpDeluxe does require some prerequisite that is required (and not automatically installed by FPCUpDeluxe) then it will try and tell what exactly is missing in the progress window (sometimes even with instructions on how to install). Information might differ depending on the host platform though.

Quote
Or do you just mean a working OS with a folder called "bin" that's in the OS search path?
No paths, no specific directories and please do not use system wide directories for FPCUpDeluxe's installations. Doing so would defeat the purpose of the program.

Quote
It's also not clear from your "fpcupdeluxe" instructions if they will leave me with a Lazarus which runs in macOS but which is able to cross-compile to Windows on demand.
The instructions as shown should do that for you. That is why I tested it  :)

Ofc. with the side-note that platform specific compiler and build-options needs to be accounted for.

Quote
Another point is that the "-WM11.0" in the Project Options is to ensure that the resultant macOS executable respond to the macOS theme, dark or light. 
Yes, but it is macos specific. It will make the cross-build to windows fail. So the option needs to be enabled when building for macos and disabled when (cross)build for windows. I edited my previous post (later) to refer to the project build-modes option and which contains a link. Please re-read and checkout the link.

Quote
UPDATE: Okay I've been looking more closely at your instructions, and given that I'm quite happy with my current 3.3.1 + 3.99 macOS combo. it seems that I only really need to consider the steps from "press the tab cross" onwards, since they seem to deal with the addition of the cross-compiler components.
Correct.

Quote
I'm guessing that I need to repeat the...
Code: Text  [Select][+][-]
  1. * select from left X86_64
  2. * select from right windows
  3. * press button "install compiler"
  4.  
...steps for as many different extra target platforms as I need. These would be Mac (Intel), Linux and Windows.
Again correct  :)

One big warning though: MAKE SURE THAT YOU SELECT THE CORRECT LAZARUS INSTALLATION PATH PRIOR TO DOING SO

I shout it because whenever I download FPCUpDeluxe to test things like this I forget to do that and end up with a system wide installation  >:(

Quote
Does that sound like a reasonable basis for my next steps?
Yes. but with some side notes.

1. you can have as many different Lazarus installations on your system at the same time (which incorporate the FPC command-line compiler and optional cross-compiler(s)). You can do that as long as they are stored inside another directory (anywhere on your system and where you have access rights).

2. In case you opt for having multiple installations alongside each other then make sure that FPCUpDeluxe points to the correct installation path on you system in case wanting to add new cross-compiler(s) and also make sure you do not accidentally use the wrong version for adding the cross-compiler(s). The versions need to match.

That is what makes it difficult to add a cross-compiler to an already installed trunk versions of Lazarus because it might happen that trunk was updated to support only newer unit versions.

I do not have enough knowledge about FPCUpDeluxe to know if it is able to recognize this situation and react accordingly (I personally do all my installations manually and from source).

3. in case you want a newer trunk version (3.99 for Lazarus and 3.3.1 for FPC) (e.g. update) then you need to select the update button instead (but there is always the small risk that it will be able to bork your current installation so be aware. Also here I do not have enough knowledge about FPCUpDeluxe so please do take precautions and make a backup first to make sure).

In case you do decide to setup different installations on a single system and in case you happen to install f.e. version 3.4 of Lazarus twice (but into different directories) then be aware that to my knowledge FPCUpDeluxe will only create a single link in your startup menu/desktop folder and that might cause confusion. As long as you are aware then it is a situation that can be worked around


Quote
Thanks again!
You're welcome. Don't forget to also have some fun !  :)

PS: The bin folder that I used in my example can be located anywhere on your system. It does not even has to be named bin, I simply used it as an example to separate FPCUpDeluxe from the Lazarus installation. They can even be located on different drives if you want to.

Personally I have created a group named "developers" that have access to a user folder named "apps" in which I created the subfolders "fpc" and "lazarus" (e.g. I do not have FPC installed inside the Lazarus folder like FPCUpDeluxe does).

PPS: If you have some time in the future then try to remove the system wide installation from your system. It will remove any (future) confusion.

PPPS: I have attached a tree of my FPCUpDeluxe installation that I used for compiling your project so that you are able to see and/or compare. Of course my x86_64-linux directory would (most probably) be your aarch64-darwin directory
« Last Edit: October 14, 2024, 03:27:24 am by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #37 on: October 14, 2024, 01:50:12 pm »
First the good news: the OsmosePresets project builds in both macOS and Windows mode (Linux to follow shortly!).

The bad news is that with the macOS version, the app is not closing down properly. It just gives the revolving wheel of doom and necessitates a Force Quit. It didn't use to do this before the "fpcupdeluxe" changes :o

Again, it pains me to say it, but the Windows version terminates properly...

Project attached...
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #38 on: October 14, 2024, 05:18:11 pm »
Problem solved. It was a coding error, that for some reason, didn't manifest itself until after the "fpcupdeluxe" update ;)
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3619
Re: Another question about cross-compiling
« Reply #39 on: October 14, 2024, 11:08:37 pm »
Good to see that you fixed that issue and thank you for reporting back.

Also great to see that you added the build-modes. There is but a tiny remark about that.

You have now 2 build modes, windows and macos which is great.

When the windows build-mode is selected the target platform and processor are now automatically configured together with the windows specific compiler options.

However, when switching to the macos build-mode the compiler options are set as intended but the target platform and processor are set to default.

From your development machine's point of view that is ofc correct but it makes no sense for me on Linux (which... defaults to target OS linux and my default processor) ;D

You can reproduce that with trying to load the project with Lazarus on another machine, f.e. your windows vm/machine (in case you have Lazarus installed there).

(I take it that you know how to solve that yourself but in case not then feel free to ask).
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Another question about cross-compiling
« Reply #40 on: October 15, 2024, 12:44:32 am »
With one or two hiccups, I've got Windows and macOS versions of my app working from a single code base!

I take your point about the use of "default" in the macOS Project Options. I created a cross-compiler for "aarch64"/"darwin" for Silicon Macs and that apparently produced "ppca64", but I haven't worked out how to use it. I'm also hoping to do the same thing with "x86_64"/"darwin"for older Intel Macs, and I'm guessing a similar thing will need to be done for Linux.

If I may, I'll call upon your expert advice again, especially where Linux is concerned 😉
"It builds... ship it!"

 

TinyPortal © 2005-2018