-1

I want to port some of my apps to Rasberry (Arm CPU), and am looking for the easiest way to get there. My apps are C++ & Qt5 based.

I've read about cross compiling (looks like lots of headaches), and running custom Raspbian kernel under Qemo (lots of gotchas according to posts), and just installing dev environment on a real Pi (very slow).

So I wondered if there is a prebuilt VM (for x86_64) that contains a full Raspbian kernel running on QEMU that I could use as a starting point. Wouldn't this be the easiest way for getting developers to port apps?

I'm not looking for a package/software recommendation, just wondering what's the easiest path to take.

3
  • Compiling on a Pi is slow, but if you are not actually doing development work, just porting to another platform, that doesn't matter much does it? You only need to do it once every time you have a new release, and while compiling on a real Pi is slow, it is also the easiest and most surefire method. Unless you have something truly colossal, it probably won't take more than a few minutes. Also remember: You actually need to target two platforms if you want to include all Pi 3's & 4's, which commonly run 64-bit arm8 userlands.
    – goldilocks
    Nov 1, 2022 at 14:51
  • Because of some platform differences I will be doing a fair bit of coding to port my apps. So compiling on a pi would be out for the reason you point out.
    – TSG
    Nov 1, 2022 at 15:22
  • 1
    Okay, but do those "platform differences" really require you work on the Pi? I'm assuming you mean a different interface, etc., or something else which is technically not platform specific (ie., unless you are doing things that can only be compiled on ARM, which in context would be very weird, or stuff that involves the GPIO interface). If it has to do with peculiarities of RpiOS, there is an x86-64 version of that you could use.
    – goldilocks
    Nov 1, 2022 at 15:38

1 Answer 1

0

You don't usually need a full VM, you just need qemu-user-static and a chroot with the Raspberry Pi OS sysroot.

On Ubuntu, you can get this really easily using some standard development tools like mk-sbuild.

# Install the tools for the host
sudo apt install sbuild ubuntu-dev-tools
# Get the Raspberry Pi OS public key
wget -qO- https://archive.raspbian.org/raspbian.public.key | gpg --import -
# Use debootstrap to create a RPi OS chroot/sysroot
mk-sbuild --arch=armhf buster --debootstrap-mirror=http://raspbian.raspberrypi.org/raspbian --name=rpizero-buster --debootstrap-keyring "$HOME/.gnupg/pubring.kbx --merged-usr" --skip-proposed --skip-updates --skip-security
# Install packages to the sysroot
sudo sbuild-apt rpizero-buster-armhf apt-get install build-essential
# Access an emulated shell in the chroot
schroot -c rpizero-buster-armhf
# Run GCC (emulated)
(rpizero-buster-armhf):/$ gcc --version
gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

More information here: Ubuntu to Raspberry Pi OS Cross C++ Development: Development setup
The guide then goes into the process of cross-compilation, but you can also just invoke your build tools and compilers in the emulated RPi OS schroot, as shown in the snippet above. However, cross compilation is not that much more work if you've already got a full RPi OS sysroot+package manager anyway, and it will be significantly faster and more convenient than building in an emulator.

Alternatively, you can build a Docker container from the RPi OS image and run that. Basically, use docker import to create an image from the RPi OS image or sysroot, then make sure you have docker/binfmt so you can emulate ARM containers, and start a container from the image you imported. The principle is very similar to the chroot described earlier, but you have a nicely packaged Docker image that you could share.
Full instructions: https://raspberrypi.stackexchange.com/a/109524/107831

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.