How do I prepare a Raspberry Pi with Raspbian so I can cross compile Qt5 programs from a Linux host?

后端 未结 2 891
南笙
南笙 2020-12-18 12:07

I want to setup a cross compile environment on Linux for the Raspberry Pi 1. Especially I want to try bleeding edge version, i.e. Raspbian testing + Qt5 dev branch.

<
相关标签:
2条回答
  • 2020-12-18 12:48

    Installing a bleeding edge development system/toolchain is a bit of a problem... It is a moving target. The following steps did work for me March 2015. If they still 100% work or how long they will work... But if one have read and understood the following 'walktrough' it should not be difficult to adjust the process for future Raspian or Qt5 versions.

    Fist step should be to update Raspian. I upgraded to testing. To do this, change the repository in /etc/apt/sources.list to:

    deb http://mirrordirector.raspbian.org/raspbian/ testing main contrib non-free rpi

    Followed by the usual 'apt-get update, apt-get upgrade, apt-get dist-upgrade'. Or an analogue aptitude command. After this step one has upgraded to the most recent Raspian. With all the risks and benefits of a testing release.

    Next a couple of packages needs to be installed. Probably not all necessary, e.g. xcb does not work on a RPi, and the RPi hat its own set of opengl files. But some Raspian packages don't know this and might pull them in anyways. The packages below allow to compile a Qt5 with QMultimedia and

    apt-get install -y "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libicu-dev libxslt1-dev 
    apt-get install -y libssl-dev libxcursor-dev libxrandr-dev libfontconfig1-dev libcap-dev libbz2-dev libgcrypt11-dev 
    apt-get install -y libpci-dev libnss3-dev libxtst-dev libasound2-dev libcups2-dev libpulse-dev libudev-dev 
    apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libproxy-dev libmtdev-dev libts-dev  
    apt-get install -y libxkbcommon-x11-dev libxkbcommon-dev libinput-dev libgbm-dev libjpeg8-dev  libgif-dev libopenjpeg-dev 
    apt-get install -y libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev sqlite3 libsqlite3-dev libwayland-dev 
    apt-get install -y libdirectfb-dev libegl1-mesa-dev  libsystemd-journal-dev libharfbuzz-dev xutils-dev libcairo2-dev
    apt-get install -y libffi-dev libpam0g-dev
    

    The next and most important step is also the most unpleasant one. A couple of libraries in Raspian are symbolic links with absolute paths. This is bad since those libraries are later on not found when Qt5 is compiled. All symlinks of relevant libs must be turned into symlinks with relative paths. With Google's help a script can be found, which did this almost automatically, but for some reason it did not work for me. Therefore I did it manually. If I have to do this more often, I certainly will write my own. This is also the step, which is most likely to break. Library versions change... so don't blindly copy/paste the commands below.

    Not all of the libs below are necessary to compile Qt5, but all of them could be a problem eventually. After this step the Raspberry Pi is ready to be used. Next step is to compile and install Qt5.

    EDIT: One of the side effects of writing such a mini-tutorial: One thinks again about certain things one has done. There is a much easier way to convert absolute links into relative links: symlinks.

    So:

    apt-get install symlinks

    And then in /usr/lib/ on the Raspberry Pi:

    symlinks -cr .

    0 讨论(0)
  • 2020-12-18 13:04

    A full toolchain is what you need

    A toolchain is a set of tools working together to generate binaries for your system. Depending on how you build your toolchain, it might end up in being only functional for your own image, that's not, in fact a problem, you just clone your image and upgrade it at will.

    First, understand what you need:

    • Functional flagship system. This is your reference board and your reference distro bundle, your packages and your stuff. You might want a standard Raspbian or you might want some extra stuff, like OpenCV or less stuff like removing Xorg. You say you want bleeding edge, so fit your taste.
    • Sysroot. Ideally this is a copy of your Functional Flagship System with the added development headers. In my case its exactly the same, for Raspbian this is an image of your second partition, the one that hosts /.
    • Cross compiler. This is a compiler that generates code for ARM while running on x86 or x86_64. This is generally a specialized gcc.
    • Cross compiled qmake. For Qt you need a cross qmake, this is a qmake that will generate Qt binaries and uses things you need to generate your arm Qt software.
    • ARM Qt libraries. This is part of your Functional Flagship System, I just enumerate it here for the sake of clarity. They will get compiled by you using your sysroot and your cross compiler.
    • Qt Libraries for Cross Compiling. This are a product of the steps you will follow when generating your cross compiling qmake and ARM Qt Libraries. This will be installed in your host x86 system.

    So how do you get all of this?

    Gather Your Very Own Toolchain

    • Functional Flagship System (FFF). Just get your raspbian image and install your additional software at will, whatever you want to be in, just install it on a live Raspberry.
    • Sysroot. Once you have your FFF, then use dd to generate an image of your second raspbian partition. Get your card off, insert it into a x86 system and use dd. There are other ways using mount and offsets but this is a lot simpler.
    • Cross compiler. Unless you really know what you are doing, just refrain from creating it yourself. There are functional cross compilers.
    • Qmake for cross compiling, ARM Qt and Qt Libraries. This is the interesting part...

    Cross Compiling Qt 5

    You can go as bleeding edge as you please with Qt as you get it from git. As this is not really a Wiki I will just enumerate the steps. This guide explains it with a lot more detail.

    1. Get your FFF, image and cross compiler working.
    2. git clone your Qt, pick a tag (version)
    3. mount your sysroot
    4. Get ia32-libs if you are under x64
    5. Compile qtbase then make install. IMPORTANT: After you get qtbase it generates it's own qmake, use it from now on.
    6. Use the generated and installed qmake from qtbase to build any other Qt module you want.
    7. Remember to use make install on all Qt modules you build. All these 'installs' will copy those binaries to your sysroot.
    8. Get your Qt into your FFF. Either you copy the folder and avoid messing with permissions, or more easily just umount your sysroot, then use dd to dump the modified image to the very same physical partition you got it from. These are the ARM Qt Libraries.
    9. When building qtbase it will install some stuff into your own x86 system. This is Qmake for cross compiling, use it into Qt Creator to generate cross compiled binaries along with your cross compiler.

    Some notes nobody tells you

    • There seem to be no toolchains ready to download. This is because they depend a lot on your specific setup.
    • Do not use system or regular qmake to cross compile. Use your generated qmake, as it fits perfectly with your FFF, it has paths and other specific stuff baked in.
    • I repeat, do not bother creating your cross compiler
    • What if you need additional development files? Install them on your FFF, then copy your partition to have your new sysroot.
    • Yes, you can auto-deploy with Qt and even debug remotely on a live Pi.
    0 讨论(0)
提交回复
热议问题