Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 6:01 pm

I have just ordered an RPi5B 8GB unit and I am interested to know if I have to recompile everything done on RPi4B for it to run on Rpi5B?
And I have two versions of RPi4B devices running bookworm, one 64 bit and the other 32 bit.
Can programs built on both run on the RPi5B?
So can RPi5B with PiOs 64 bit run both 32 and 64 bit older programs.
I assume RPi5B always runs 64 bit OS....
Bo Berglund
Sweden

Abmvk
Posts: 259
Joined: Sat Feb 04, 2023 10:07 pm
Location: Netherlands

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 6:41 pm

I think you shouldn’t have a problem. The other day I needed a program I wrote in C on my 4B, compiled it on the 4B, and needed to run it on the 5. No problem at all. Just copied it and it worked

NotRequired
Posts: 426
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 7:54 pm

You cannot assume that it will work, but some of it might. With Linux, you should always compile code on the host where possible.
Glowing in the dark!

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 8:09 pm

OK, so the RPi5B uses the same type of ARM CPU as the RPi4B then?
From Windows migration there was always possible to run older programs on newer operating systems but not the other way around.
Does this depend on the 32/64 bit selection of PiOS?
So that on 32 bit PiOS old 32 bit code runs but not on 64 bit Pi-OS?

Extreme case:
Compiled on RPi3B with 32 bit Buster Raspbian => moved to RPi5B with 64 bit PiOS. Does it run?

Cannot test myself yet, waiting for delivery...
Bo Berglund
Sweden

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 8:10 pm

Abmvk wrote:
Tue Dec 05, 2023 6:41 pm
I think you shouldn’t have a problem. The other day I needed a program I wrote in C on my 4B, compiled it on the 4B, and needed to run it on the 5. No problem at all. Just copied it and it worked
And the RPi5B ran the 64 bit PiOS?
Bo Berglund
Sweden

ejolson
Posts: 12171
Joined: Tue Mar 18, 2014 11:47 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 8:13 pm

Bosse_B wrote:
Tue Dec 05, 2023 6:01 pm
I have just ordered an RPi5B 8GB unit and I am interested to know if I have to recompile everything done on RPi4B for it to run on Rpi5B?
And I have two versions of RPi4B devices running bookworm, one 64 bit and the other 32 bit.
Can programs built on both run on the RPi5B?
So can RPi5B with PiOs 64 bit run both 32 and 64 bit older programs.
I assume RPi5B always runs 64 bit OS....
Since the 64-bit version of Raspberry Pi OS is not multiarch

https://wiki.debian.org/Multiarch/HOWTO

then 32-bit software will not run because the needed 32-bit dynamic libraries are missing.

I've not tried adding 32-bit ARM architecture to the 64-bit release of Raspberry Pi OS following the above linked HowTo. That is an interesting idea that might go wrong.

These days I'd suggest creating a 32-bit Docker container to run old 32-bit binaries that are not possible to recompile for 64-bit mode.

User avatar
dickon
Posts: 2599
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, in Tiffield

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 8:51 pm

Bosse_B wrote:
Tue Dec 05, 2023 6:01 pm
I have just ordered an RPi5B 8GB unit and I am interested to know if I have to recompile everything done on RPi4B for it to run on Rpi5B?
And I have two versions of RPi4B devices running bookworm, one 64 bit and the other 32 bit.
Can programs built on both run on the RPi5B?
So can RPi5B with PiOs 64 bit run both 32 and 64 bit older programs.
I assume RPi5B always runs 64 bit OS....
The Pi 5 has Cortex A76 cores; the Pi 4 has A72s. The biggest difference is that the A76 doesn't have aarch32 support in EL1, which means you must be running a 64b kernel. You could run a 32b userland with a 64b kernel, however.

Normal userland programs should just work as usual. I assume the 32b images ship with 64b kernels for the 5, but I can't say I've checked.
As it is apparently board policy to disallow any criticism of anything, as it appears to criticise something is to criticise all the users of that something, I will no longer be commenting in threads which are not directly relevant to my uses of the Pi.

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 10:01 pm

dickon wrote:
Tue Dec 05, 2023 8:51 pm
Bosse_B wrote:
Tue Dec 05, 2023 6:01 pm
I have just ordered an RPi5B 8GB unit and I am interested to know if I have to recompile everything done on RPi4B for it to run on Rpi5B?
And I have two versions of RPi4B devices running bookworm, one 64 bit and the other 32 bit.
Can programs built on both run on the RPi5B?
So can RPi5B with PiOs 64 bit run both 32 and 64 bit older programs.
I assume RPi5B always runs 64 bit OS....
The Pi 5 has Cortex A76 cores; the Pi 4 has A72s. The biggest difference is that the A76 doesn't have aarch32 support in EL1, which means you must be running a 64b kernel. You could run a 32b userland with a 64b kernel, however.
Normal userland programs should just work as usual. I assume the 32b images ship with 64b kernels for the 5, but I can't say I've checked.
The Pi-Imager offers both 32 and 64 bit Pi-OS for the Pi5B, so it is capable of both...
And it does the same for Pi4B, which I have, so I can check directly on the 54 bit device I built a few weeks back.

But my thoughts are about older programs that need to be recompiled for the new CPU/Bitsize in order to be used on the new systems.
But I guess this is the same as right now with 32/64 bit bookworm PiOS...

All code that is python based is probably just fine (my coding is not using python, though).

Thanks for your comments!
Bo Berglund
Sweden

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 10:53 pm

Follow-up:
I created a simple GUI hello program on an RPi4B running buster and copied it onto an RPi4B running PiOS 64 bit bookworm.
Then I tried starting it like I did on the source RPi4B.
This is the response:

Code: Select all

$ ./hello 
bash: ./hello: cannot execute: required file not found
(No info on what file it deemed required).

So apparently it is not possible to run 32 bit programs on 64 bit PiOS...
Bo Berglund
Sweden

cleverca22
Posts: 8637
Joined: Sat Aug 18, 2012 2:33 pm

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 10:57 pm

Bosse_B wrote:
Tue Dec 05, 2023 10:01 pm
But my thoughts are about older programs that need to be recompiled for the new CPU/Bitsize in order to be used on the new systems.
if the program was compiled in 32bit mode, then you need a 32bit os, it doesnt matter what the cpu supports (or a multilib 32+64bit os)

if the program was compiled in 64bit mode, then you need a 64bit os (and a 64bit capable cpu, to boot it)
Bosse_B wrote:
Tue Dec 05, 2023 10:53 pm
So apparently it is not possible to run 32 bit programs on 64 bit PiOS...
run file on that binary, and youll see the interpreter path, that needs to exist (or it needs to be a static binary) for things to work

a multilib install, has support for both 32bit and 64bit
but 64bit pios isnt multilib, so you need:
  • a static 32bit binary
  • a 64bit dynamic binary
  • a docker container with the needed 32bit interpreter and libs

Abmvk
Posts: 259
Joined: Sat Feb 04, 2023 10:07 pm
Location: Netherlands

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Tue Dec 05, 2023 11:48 pm

Bosse_B wrote:
Tue Dec 05, 2023 8:10 pm
Abmvk wrote:
Tue Dec 05, 2023 6:41 pm
I think you shouldn’t have a problem. The other day I needed a program I wrote in C on my 4B, compiled it on the 4B, and needed to run it on the 5. No problem at all. Just copied it and it worked
And the RPi5B ran the 64 bit PiOS?
yes, as did the 4B

pidd
Posts: 5585
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 4:02 am

ejolson wrote:
Tue Dec 05, 2023 8:13 pm
Since the 64-bit version of Raspberry Pi OS is not multiarch

64-bit bullseye was multiarch and bookworm is as well

Code: Select all

$ dpkg --print-foreign-architectures
armhf

ejolson
Posts: 12171
Joined: Tue Mar 18, 2014 11:47 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 4:09 am

pidd wrote:
Wed Dec 06, 2023 4:02 am
ejolson wrote:
Tue Dec 05, 2023 8:13 pm
Since the 64-bit version of Raspberry Pi OS is not multiarch
64-bit bullseye was multiarch and bookworm is as well

Code: Select all

$ dpkg --print-foreign-architectures
armhf
That's great news! Does the 64-bit SD card image come with the libraries needed for multiarch support or does one have to install them later?

Hm. There are a bunch of 32-bit libraries in /lib/arm-linux-gnueabihf so maybe multiarch is already included.

cleverca22
Posts: 8637
Joined: Sat Aug 18, 2012 2:33 pm

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 4:41 am

ejolson wrote:
Wed Dec 06, 2023 4:09 am
Hm. There are a bunch of 32-bit libraries in /lib/arm-linux-gnueabihf so maybe multiarch is already included.
i have a fresh install of 64bit bookworm, and those are missing on my end

Code: Select all

clever@raspberrypi:~ $ dpkg --print-foreign-architectures
armhf
clever@raspberrypi:~ $ ls /lib/arm-linux-gnueabihf
ls: cannot access '/lib/arm-linux-gnueabihf': No such file or directory
clever@raspberrypi:~ $ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"

ejolson
Posts: 12171
Joined: Tue Mar 18, 2014 11:47 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 5:08 am

cleverca22 wrote:
Wed Dec 06, 2023 4:41 am
ejolson wrote:
Wed Dec 06, 2023 4:09 am
Hm. There are a bunch of 32-bit libraries in /lib/arm-linux-gnueabihf so maybe multiarch is already included.
i have a fresh install of 64bit bookworm, and those are missing on my end

Code: Select all

clever@raspberrypi:~ $ dpkg --print-foreign-architectures
armhf
clever@raspberrypi:~ $ ls /lib/arm-linux-gnueabihf
ls: cannot access '/lib/arm-linux-gnueabihf': No such file or directory
clever@raspberrypi:~ $ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
Oops. I did not check a new image but one that's been used for some time.

cleverca22
Posts: 8637
Joined: Sat Aug 18, 2012 2:33 pm

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 5:22 am

ejolson wrote:
Wed Dec 06, 2023 5:08 am
Oops. I did not check a new image but one that's been used for some time.
i'm guessing that apt is setup to support multi-lib, and it will install the 32bit libs, if something in apt needs them

but if you download something without apt, it wont add them, and things may fail, and now you have a whole "but it works on my machine" problem

redvli
Posts: 1735
Joined: Thu Sep 03, 2020 8:09 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 9:18 am

cleverca22 wrote:
Wed Dec 06, 2023 5:22 am
ejolson wrote:
Wed Dec 06, 2023 5:08 am
Oops. I did not check a new image but one that's been used for some time.
i'm guessing that apt is setup to support multi-lib, and it will install the 32bit libs, if something in apt needs them

but if you download something without apt, it wont add them, and things may fail, and now you have a whole "but it works on my machine" problem
Earlier when Google had not released widevine for aarch64 Linux, I used the 32-bit chromium-browser +32-bit widevine on 64-bit RPiOS bullseye on Pi4 v1.1. As suggested on the Pi social weblog on this domain. It fetched all armhf libs that were needed. When switched to 64-bit chromium, I did not explicitly remove all armhf packages, did that after dist-upgrade bookworm worked. Some w.r.t. gcc need apt-get to remove, those are seen as essential although they aren't if you have nothing that needs armhf. Did the same earlier with in-place upgrade from RPiOS64 bullseye to Debian Trixie aarch64.
If I wouldn't have done it, I would still be able to create 32-bit binaries I think, but not tested and also not needed. It are Pi3B, Pi3B+, Pi4B. They can easily run/start a 32-bit VM if I need, I have converted RPiOS bookworm 2023-10-10 to run as VM, good for seeing what RPL does with upgrades etc before I apply to my slow remote Pi1 and Pi0.

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Wed Dec 06, 2023 10:09 pm

pidd wrote:
Wed Dec 06, 2023 4:02 am
64-bit bullseye was multiarch and bookworm is as well

Code: Select all

$ dpkg --print-foreign-architectures
armhf
Good to know, so I have checked my two RPi4B installations:

Code: Select all

32-bit bookworm:
bosse@rpi4-dev2b:~ $ dpkg --print-foreign-architectures
arm64

64-bit bookworm:
bosse@rpi4-dev2b:~ $ dpkg --print-foreign-architectures
armhf
So seemingly these platforms accept foreign applications in binary compiled format?
Well, I have tested it earlier by copying a helloworld program from 32 bit bullseye to 64 bit bookworm and it did not start.
I have not tested with just using the two bookworm systems and exchange applications between them...
Bo Berglund
Sweden

pidd
Posts: 5585
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 12:34 am

Bosse_B wrote:
Wed Dec 06, 2023 10:09 pm
Well, I have tested it earlier by copying a helloworld program from 32 bit bullseye to 64 bit bookworm and it did not start.
I have not tested with just using the two bookworm systems and exchange applications between them...

The 32 bit runtime libraries might be missing if you just copy a binary across.

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 7:26 am

Bosse_B wrote:
Wed Dec 06, 2023 10:09 pm
Well, I have tested it earlier by copying a helloworld program from 32 bit bullseye to 64 bit bookworm and it did not start.
I have not tested with just using the two bookworm systems and exchange applications between them...
The reason I have not been able to test this on bookworm 32 => 64 bit is that I cannot get VNC working on the 32 bit systems so I cannot even use the development IDE on them (I run all of my RPi devices headless relying solely on SSH and VNC to control them).
It seems like VNC is fully broken on bookworm Pi-OS 32 bit but can be made to work on 64 bit if one enables the use of the X11 desktop manager.
pidd wrote:
Thu Dec 07, 2023 12:34 am
The 32 bit runtime libraries might be missing if you just copy a binary across.
I have never before needed to transfer any libraries when putting an application on to a Raspberry...
I do not even use external libraries with my applications.
Back in the old Windows days the hassle with OCX and DLL dependencies was the reason we switched around 1995 from Microsoft dev tools to using Borland Delphi, which produced standalone exe files.

Note:
I develop using FreePascal with Lazarus as the dev IDE and that creates compiled stand-alone binaries which only need to be copied into the target system in order to work.
The FreePascal/Lazarus system is an enhanced multi-platform open-source clone of Delphi, and I have been using it for about 15 years now for new applications.

This has worked on Windows and Linux for many years even when Windows went from 32 to 64 bit and I was hoping it would also work when PiOS went from 32 to 64 bit. I don't think I had started using Linux on the PC platform before Ubuntu was 64 bit...
Back in 2012 my only Linux systems were RaspberryPi (I was on the waiting list to get it when it was first released).

But direct transfer of binaries seems not to work on RPi4B... :(

And there is apparently no difference for the RPi5B then?
Bo Berglund
Sweden

redvli
Posts: 1735
Joined: Thu Sep 03, 2020 8:09 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 9:44 am

Bosse_B wrote:
Tue Dec 05, 2023 10:53 pm
Follow-up:
I created a simple GUI hello program on an RPi4B running buster and copied it onto an RPi4B running PiOS 64 bit bookworm.
Then I tried starting it like I did on the source RPi4B.
This is the response:

Code: Select all

$ ./hello 
bash: ./hello: cannot execute: required file not found
If that program is created with that Lazarus IDE, changes are high that it takes or assumes stuff from the wrong dev libraries.
Run it with:
sudo strace hello
then you might see what is missing.

cleverca22
Posts: 8637
Joined: Sat Aug 18, 2012 2:33 pm

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 9:49 am

sudo is not needed there

mrlinux2u
Posts: 380
Joined: Sat Sep 24, 2011 8:38 pm

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 10:03 am

FYI, I've just copied one of my Lazarus programs (compiled on 32bit Bullseye) and copied it onto my works Pi 5 running 32bit Bookworm and it ran without any issues.

I'll try and run the same program later today when I get home on my Pi 5 (running 64bit Bookworm) to see it works or if I need to re-compile it for a 64bit environment (or need to install the 32bit libraries).

One (really) good thing about developing on a Pi 5 is that Lazarus runs much faster (and smoother) than on a Pi 4 which can only be a good thing in the long term.

Bosse_B
Posts: 1511
Joined: Thu Jan 30, 2014 9:53 am

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 11:50 am

mrlinux2u wrote:
Thu Dec 07, 2023 10:03 am
FYI, I've just copied one of my Lazarus programs (compiled on 32bit Bullseye) and copied it onto my works Pi 5 running 32bit Bookworm and it ran without any issues.

I'll try and run the same program later today when I get home on my Pi 5 (running 64bit Bookworm) to see it works or if I need to re-compile it for a 64bit environment (or need to install the 32bit libraries).

One (really) good thing about developing on a Pi 5 is that Lazarus runs much faster (and smoother) than on a Pi 4 which can only be a good thing in the long term.
Are you running your RPi with a monitor attached?
I don't because I don't have space for another monitor in my crammed study so I use VNC, and also because I have so many RPi devices running I always use them headless through VNC and SSH.
But VNC does not work at all on 32 bit bookworm and on 64 bit only after switching to the X11 desktop in raspi-config.
So I have no way to use Lazarus on the 32 bit bookworm machine... :(

I am eagerly waiting for my RPi5B kit ordered a few days ago to arrive... :)
Bo Berglund
Sweden

mrlinux2u
Posts: 380
Joined: Sat Sep 24, 2011 8:38 pm

Re: Can RPi5 run binaries compiled on RPi4 bookworm?

Thu Dec 07, 2023 12:05 pm

Bosse_B wrote:
Thu Dec 07, 2023 11:50 am
mrlinux2u wrote:
Thu Dec 07, 2023 10:03 am
FYI, I've just copied one of my Lazarus programs (compiled on 32bit Bullseye) and copied it onto my works Pi 5 running 32bit Bookworm and it ran without any issues.

I'll try and run the same program later today when I get home on my Pi 5 (running 64bit Bookworm) to see it works or if I need to re-compile it for a 64bit environment (or need to install the 32bit libraries).

One (really) good thing about developing on a Pi 5 is that Lazarus runs much faster (and smoother) than on a Pi 4 which can only be a good thing in the long term.
Are you running your RPi with a monitor attached?
I don't because I don't have space for another monitor in my crammed study so I use VNC, and also because I have so many RPi devices running I always use them headless through VNC and SSH.
But VNC does not work at all on 32 bit bookworm and on 64 bit only after switching to the X11 desktop in raspi-config.
So I have no way to use Lazarus on the 32 bit bookworm machine... :(

I am eagerly waiting for my RPi5B kit ordered a few days ago to arrive... :)
I'm running XRDP server (headless) on my Pi 5 (running with X11/XFCE4) and accessing it via Remmina and it's more than fast enough (it's faster than my overclocked Pi 4 I use to access it even remotely).

Return to “Raspberry Pi OS”