Recent

Author Topic: Cross-platform - how to target Linux  (Read 3399 times)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Cross-platform - how to target Linux
« on: October 15, 2024, 10:32:08 pm »
* Mac Mini M1
* macOS 14.6.1
* Lazarus 3.99
* FPC 3.3.1

I've been working on an application which work with MIDI and it uses a simple, interface based framework to allow the OS specific MIDI code to be isolated into separate units. So far I have used "fpcupdeluxe' to build a cross-compiler for Windows and (with lots of help from @TRon 🙏🏽) it works pretty well.

Now, it's time to tackle Linux! Before diving into the MIDI innards of Linux, whether this be Alsa or some other library, I just want to get the basics of building the correct cross-compiler.
The first choice I face is choosing a distro for my VMWare Fusion VM. I can choose from...
Code: Text  [Select][+][-]
  1. Alma Linux 64-bit Arm
  2. Debian 12.x 64-bit Arm
  3. Debian 11.x 64-bit Arm
  4. Debian 10.x 64-bit Arm
  5. Fedora 64-bit Arm
  6. Red Hat Enterprise Linux 9 64-bit Arm
  7. Rocky Linux 64-bit Arm
  8. Ubuntu 64-bit Arm
  9. VMWare Photon 64-bit Arm
  10. Other Linux 6.x kernel 64-bit Arm
  11. Other Linux 5.x kernel 64-bit Arm
  12.  

I'm guessing that VMWare is only offering me Arm distros, because my VMWare is running on macOS 14.6.1 on a Mac Midi M1, and that any Linux executables produced with it will run on a wide range of target distros... or is the idea to offer a source only download and let the users build it themselves?

I'm drawn towards Ubuntu largely because it is a popular distro, and I've used it before!

In terms of using "fpcupdeluxe" to build a cross-compiler, I'm guessing that I need to use a "lowest common denominator" approach and select "x86_64" for the CPU and "Linux" for the OS.

If anyone could tell me if I'm on the right lines with my thinking, I'd really appreciate it 😃
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3957
Re: Cross-platform - how to target Linux
« Reply #1 on: October 15, 2024, 11:15:38 pm »
Quick word of warning: choosing which version of linux to install/support might have more implications than you perhaps are able to imagine (though FPCUpDeluxe has some counter measures but those aren't officially supported).

Linux went through some transformation with regards to libc (a library that most LCL applications will link to) where your apps compiled for debian 12 (the one I am familiar with) will not be able to run on debian 11 machines. Since many distro's are based on debian this issue also arise for all those distribution that are based on debian (including ubuntu).

The only other thing I can say about it is choose a distribution that is supported by FPCUpDeluxe as that makes life a lot easier.

In order to be able to cross-compile to linux a lot of other dependencies need to be installed so that the cross-compiler is able to link against it and FPCUpdeluxe will try and download/configure these dependencies automatically for you.

This is completely different than cross-compiling for Windows, which requires no dependencies whatsoever (other than the binutils).
I do not have to remember anything anymore thanks to total-recall.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8213
Re: Cross-platform - how to target Linux
« Reply #2 on: October 15, 2024, 11:34:54 pm »
Linux went through some transformation with regards to libc (a library that most LCL applications will link to) where your apps compiled for debian 12 (the one I am familiar with) will not be able to run on debian 11 machines. Since many distro's are based on debian this issue also arise for all those distribution that are based on debian (including ubuntu).

There's also some very painful issues relating to the structure of the ELF file generated by FPC 3.2, which is different from earlier versions.

Thread ending at https://forum.lazarus.freepascal.org/index.php/topic,61001.msg532347.html#msg532347 applies.

Basically, the position of the project as explained to me was that FPC/Lazarus allowed a collection of source files to be compiled on a fairly wide selection of systems, but did not promise that a binary built on one system would work on another.

It was actually put somewhat less gently than that, and I am still unhappy about it.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Cross-platform - how to target Linux
« Reply #3 on: October 16, 2024, 12:56:15 am »
Thanks chaps for your words of warning!

I've had a pretty successful evening installing Ubuntu 24.10 in VMWare Fusion. It was a struggle at first until I sussed out that the plain old "UK Keyboard" was the one to go for, and that any mention of "Macintosh" in the Ubuntu keyboard settings should be thoroughly disregarded 😉

I also managed to get the "open-vm-tools" as opposed to the VMWare Tools installed, giving me nice feature like shared clipboard, and drag'n'drop file transfers, apparently.

I'll cross the bridge of trying to get a simple Lazarus app built and running in Ubuntu, tomorrow. What could possibly go wrong? 😉
« Last Edit: October 16, 2024, 11:08:14 am by carl_caulkett »
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3957
Re: Cross-platform - how to target Linux
« Reply #4 on: October 16, 2024, 01:13:17 am »
I'll cross the bridge of trying to get a simple Lazarus app built and running in Ubuntu, tomorrow. What could possibly go wrong? 😉
I'll wish you all the luck and indeed.. the famous last words  :D

(you should be fine with FPCUpDeluxe but in case issues arise then please feel free to report).
I do not have to remember anything anymore thanks to total-recall.

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Cross-platform - how to target Linux
« Reply #5 on: October 16, 2024, 03:24:53 pm »
I used "fpcupdeluxe" to build cross-compilers for "x86_64/linux" and "arm/linux", and was able to build executables for both modes. However, when I try to run either of them, I get errors...

I'm pretty much at the limits of my Linux-fu, though, admittedly that's a pretty low bar ;)
"It builds... ship it!"

MarkMLl

  • Hero Member
  • *****
  • Posts: 8213
Re: Cross-platform - how to target Linux
« Reply #6 on: October 16, 2024, 03:34:49 pm »
Did you say that you were running Debian 12, and what version of FPC was used to build those binaries?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Cross-platform - how to target Linux
« Reply #7 on: October 16, 2024, 03:51:59 pm »
I'm running Ubuntu 24.10 (dunno if that's Debian 12 under the hood...). I'm using FPC 3.31 and Lazarus 3.99.

I've used uname -m to determine that my Linux VM is aarch64 architecture.

I then created an aarch64/linux cross-compiler using FpcUpDeluxe. The problem is that when I try to build the project using the appropriate options (I think), it fails to build...
Code: Text  [Select][+][-]
  1. Hint: Start of reading config file /Applications/Lazarus_trunk/fpc/bin/x86_64-darwin/fpc.cfg
  2. Hint: End of reading config file /Applications/Lazarus_trunk/fpc/bin/x86_64-darwin/fpc.cfg
  3. Verbose: Free Pascal Compiler version 3.2.2 [2021/05/16] for aarch64
  4. Debug: Copyright (c) 1993-2021 by Florian Klaempfl and others
  5. Verbose: Target OS: Linux for AArch64
  6. Verbose: Compiling testlinuxcli.lpr
  7. Verbose: PPU Loading /Applications/Lazarus_trunk/fpc/units/aarch64-linux/rtl/system.ppu
  8. Verbose: PPU Invalid Version 208
  9. Fatal: Can't find unit system used by testlinuxcli
  10. Verbose: Compilation aborted
  11. Verbose: /usr/local/bin/ppca64 returned an error exitcode
  12.  


Again, I'm sure it's something obvious that I've missed out, but I just cannot see it...
"It builds... ship it!"

MarkMLl

  • Hero Member
  • *****
  • Posts: 8213
Re: Cross-platform - how to target Linux
« Reply #8 on: October 16, 2024, 04:01:26 pm »
Don't even /think/ about trying to run that as a compiler, you'll get bogged down.

Think of it as a program for which you want to get help information, and run <whatever> -h

Do those two compilers run on your host system with the above command?

If they do, then it is probably /not/ the problem in my earlier thread, and is more connected with FPCUpDl... and I'd point out that even though you say you're running FPC 3.31 your last error message talks about 3.2.2.

There's a possibility that it's because you've tried to build cross compilers for two target architectures and didn't test each individually:

Quote
I used "fpcupdeluxe" to build cross-compilers for "x86_64/linux" and "arm/linux", and was able to build executables for both modes. However, when I try to run either of them, I get errors...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 3957
Re: Cross-platform - how to target Linux
« Reply #9 on: October 16, 2024, 04:04:24 pm »
What MarkMLI already noted in his post.

There seem to be a version mismatch between compiler and cross-compiler. That is why the error message is emitted:
"Verbose: PPU Invalid Version 208"
I do not have to remember anything anymore thanks to total-recall.

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1792
Re: Cross-platform - how to target Linux
« Reply #10 on: October 16, 2024, 04:04:34 pm »
AFAIK, there are no tools to cross towards aarch64 on Mac M1.
Did you realy succeed in building a cross-compiler ?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12037
  • FPC developer.
Re: Cross-platform - how to target Linux
« Reply #11 on: October 16, 2024, 04:21:55 pm »
Basically, the position of the project as explained to me was that FPC/Lazarus allowed a collection of source files to be compiled on a fairly wide selection of systems, but did not promise that a binary built on one system would work on another.

It was actually put somewhat less gently than that, and I am still unhappy about it.

The problem is that Linux is not very supportive of moving binaries between systems.

duralast

  • New Member
  • *
  • Posts: 23
Re: Cross-platform - how to target Linux
« Reply #12 on: October 16, 2024, 04:25:39 pm »
I'm running Ubuntu 24.10 (dunno if that's Debian 12 under the hood...).
On Ubuntu you can
Code: [Select]
$ cat /etc/debian_version
bookworm/sid
The recent versions of Debian versions/codenames are:
Quote
12 bookworm
13 trixie
14 forky

TRon

  • Hero Member
  • *****
  • Posts: 3957
Re: Cross-platform - how to target Linux
« Reply #13 on: October 16, 2024, 04:30:58 pm »
As indicated by duralast, a normal Ubuntu (there are derivatives not based on Debian) everything matching 22.04 or higher is  based on Debian 12 (or higher).

I do not know what the compatibility between higher versions of Debian currently is (we cross that bridge when we come to it).
I do not have to remember anything anymore thanks to total-recall.

carl_caulkett

  • Hero Member
  • *****
  • Posts: 649
Re: Cross-platform - how to target Linux
« Reply #14 on: October 16, 2024, 04:34:56 pm »
AFAIK, there are no tools to cross towards aarch64 on Mac M1.
Did you realy succeed in building a cross-compiler ?

So fpcupdeluxe would have me believe ;)
"It builds... ship it!"

 

TinyPortal © 2005-2018