Monday, September 9, 2019

Raspbian Buster and Cross Toolchain for Linux and Mac OS 8.3.0

Raspbian Buster is out. It seems it updated gcc from version 6.3.0 (used for Stretch) to gcc version 8.3.0. This is not always needed, but I had a lot of problems in the past related to using an outdated crosscompiler, or the one provided in the raspberry repo: https://github.com/raspberrypi/tools. I therefore built my own toolchain for Stretch, which I provided here, both for Linux and Mac OS.

I did the same for Buster: I built my own toolchain and I built many projects with it, like Qt, ffmpeg etc... Just place the toolchain in /opt/rpi (probably position independent) and you should be done. This toolchain should be 100% compatible with gcc provided by Buster.

Download cross toolchain GCC 6.3.0 for Stretch here.
Download Linux x64 cross toolchain GCC 8.3.0 here.
Download Mac OS cross toolchain GCC 8.3.0 here.

Bye ;-)

49 comments:

  1. hi
    welcome back
    do you will build new Qt version 12 or 13 for raspberry pi

    ReplyDelete
  2. Thank you Luca.
    Just for the others, your toolchain is not position independent, so it have to be placed in /opt/rpi.

    Thanks again.

    ReplyDelete
    Replies
    1. Correct. I tried to create it position independent in the past but it seemed not to work properly on mac.

      Delete
  3. Hello,

    the binaries generated when compiling works on raspberry pi 4 and raspberry pi 3?

    Thanks.
    Good job Luca.

    ReplyDelete
    Replies
    1. You I built for, at least, armv7 and armv8 with this toolchain. So rpi2, rpi3 and rpi4. Didn't try armv6.

      Delete
    2. I used this toolchain to crosscompile Qt5.12.5 for raspberry pi4 with these modules: qtdeclarative qtquickcontrols qtquickcontrols2 qtmultimedia qtsvg qtxmlpatterns qtgraphicaleffects qtwebsockets. It works like a charm!

      Delete
  4. I use this toolchain t crosscompile Qt5.12.5 for raspberry pi4 on Ubuntu 18.04 and I have this error on compile time:


    /opt/rpi/rpi-gcc-8.3.0/bin/arm-linux-gnueabihf-g++ -c -include .pch/Qt5Core -march=armv8-a -mtune=cortex-a53 -mfpu=crypto-neon-fp-armv8 -mfloat-abi=hard --sysroot=/opt/rpi/buster_enigma/sysroot/ -O3 -std=c++1z -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -Wvla -Wdate-time -Wshift-overflow=2 -Wduplicated-cond -Wno-stringop-overflow -D_REENTRANT -fPIC -DQT_NO_USING_NAMESPACE -DQT_NO_FOREACH -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_BUILD_CORE_LIB -DQT_BUILDING_QT -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -DQT_USE_QSTRINGBUILDER -DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -I. -Iglobal -I../3rdparty/harfbuzz/src -I../3rdparty/md5 -I../3rdparty/md4 -I../3rdparty/sha3 -I../3rdparty/forkfd -I../3rdparty/tinycbor/src -I../../include -I../../include/QtCore -I../../include/QtCore/5.12.5 -I../../include/QtCore/5.12.5/QtCore -I.moc -I.tracegen -isystem /opt/rpi/buster_enigma/sysroot/usr/include/glib-2.0 -I/opt/rpi/buster_enigma/sysroot/usr/lib/arm-linux-gnueabihf/glib-2.0/include -isystem /opt/rpi/buster_enigma/sysroot/usr/include -I/opt/rpi/buster_enigma/sysroot/opt/vc/include -I../../mkspecs/devices/linux-rasp-pi3-vc4-g++ -o .obj/qlockfile_unix.o io/qlockfile_unix.cpp
    io/qfilesystemengine_unix.cpp: En la función ‘int qt_statx(const char*, statx*)’:
    io/qfilesystemengine_unix.cpp:323:26: error: ‘AT_FDCWD’ no se declaró en este ámbito
    return qt_real_statx(AT_FDCWD, pathname, 0, statxBuffer);

    ReplyDelete
    Replies
    1. AT_FDCWD is defined in fcntl.h in the toolchain.

      Delete
  5. Thank you for your toolchain! It helped me getting started, but unfortunately there were some issues especially with ARMv6 support.

    I created a new repository for a toolchain based on GCC8 and ARMv6 support. Feel free to link it:

    https://github.com/Pro/raspi-toolchain

    ReplyDelete
  6. Thank you for this amazing work.
    I used this toolchain to cross compile POT, QT 5.12.5 and my QT application.
    It is a QT QML project that plays one video.

    It copied qt_driver to mediaservice and I think it is all in the rigth place.
    But my application could not run. It always stop in the problema above.
    I hope maybe someone could read this and give me some light.


    QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/qt5pi/plugins/video/videonode" ...
    QFactoryLoader::QFactoryLoader() looking at "/usr/local/qt5pi/plugins/video/videonode/libeglvideonode.so"
    Found metadata in lib /usr/local/qt5pi/plugins/video/videonode/libeglvideonode.so, metadata=
    {
    "IID": "org.qt-project.qt.sgvideonodefactory/5.2",
    "MetaData": {
    "Keys": [
    "egl"
    ]
    },
    "archreq": 0,
    "className": "QSGVideoNodeFactory_EGL",
    "debug": false,
    "version": 330752
    }


    Got keys from plugin meta data ("egl")
    QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/video/videonode" ...
    loaded library "/usr/local/qt5pi/plugins/video/videonode/libeglvideonode.so"
    Requesting control for org.qt-project.qt.videorenderercontrol/5.0...
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/qt5pi/plugins/accessible" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/accessible" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/qt5pi/plugins/accessiblebridge" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/home/pi/accessiblebridge" ...
    Bus error

    ReplyDelete
    Replies
    1. I forgot to mention that I got a message in dmesg: Unhandled prefetch abort: unknown 1 (0x001)

      Delete
    2. Is a minimal Qt app working properly? Does the app work without multimedia?
      Maybe wrong arch? What is readelf -a saying about /usr/local/qt5pi/plugins/video/videonode/libeglvideonode.so?

      Delete
    3. Thank you for the response.
      I can make a minimal app that works without multimedia.

      Tha readelf gives me:

      Attribute Section: aeabi
      File Attributes
      Tag_CPU_name: "8-A"
      Tag_CPU_arch: v8
      Tag_CPU_arch_profile: Application
      Tag_ARM_ISA_use: Yes
      Tag_THUMB_ISA_use: Thumb-2
      Tag_FP_arch: VFPv2

      when I check a random lib I got

      Attribute Section: aeabi
      File Attributes
      Tag_CPU_name: "6"
      Tag_CPU_arch: v6
      Tag_ARM_ISA_use: Yes
      Tag_THUMB_ISA_use: Thumb-1
      Tag_FP_arch: VFPv2

      Maybe I make a mistake and compile QT as armv8 instead of armv6? I tought it should be armv7. Anyway I will study more about it ..

      Delete
    4. I am using buster built using pi-gen tool.

      Delete
    5. Armv8 is ok then. You'll have to debug deeper. I'd try gdb or strace.

      Delete
    6. I will try going deeper.
      Thank you.

      Delete
    7. Hi @Gabriel
      Did you manage to solve your issue? I got the same issue like you.
      If you have any news, please share
      Thanks
      Kien

      Delete
  7. @Kien, Sorry for the late response.
    I could compile qt 5.12.5 with webengine support using the instructions here.
    https://wiki.qt.io/RaspberryPiWithWebEngine
    But I modify it to use the toolchain provided by Luca.
    One thing that I did to work was change the links to absolute path in arm-linux-gnueaubihf in the rootfs.
    After that I could compile and run POT ok.

    ReplyDelete
  8. My problem now is that WebEngineView component is using almost all cpu in my board. It works but uses 300% of cpu in top. If anyone has some tips I would appreciate

    ReplyDelete
  9. Hi luca, great work. i'm using it and it works like a charm.
    See you

    ReplyDelete
  10. Hi Luca, great work but I was wondering why you didn't include gdb in the toolchain (currently using on on Big Sur)

    ReplyDelete
    Replies
    1. Hello, I typically use gdb from the pi itself, so I was not interested.

      Delete
  11. Dear Luca,
    i am trying to use your toolchain (Linux x64) to crosscompile QT5.15.2 for the raspberry 2, Buster.
    Would you please give some advice.
    Previously i used the toolchain from: https://github.com/raspberrypi/tools
    Now, i only changed the compiler line in my ./configure.sh to point to your toolchain in /opt/rpi/

    Project ERROR: Cannot run target compiler '/opt/rpi/bin/arm-linux-gnueabihf-gcc-8.3.0g++'. Output:
    ===================
    ===================
    Maybe you forgot to setup the environment?

    ReplyDelete
    Replies
    1. Hello, I see no error reported. If you run the compiler directly, does it work?

      Delete
    2. Works now, i moved it to the wrong folder.
      The folder needs to be: /opt/rpi/rpi-gcc-8.3.0/

      Delete
  12. Dear Luca,

    i managed to crosscompile QT5.15.2 for a raspberry pi2.
    Now, I am stuck at creating the pot-tools (v5.7.3).

    I am using your toolchain from here: https://bugfreeblog.page.link/rasplinuxgcc830

    I run "./prepare_3rdparty.sh pi2" which calls ./configure for ffmpeg.

    This fails with:
    arm-linux-gnueabihf-gcc is unable to create an executable file.
    C compiler test failed.


    Some lines from the ffmpeg config.log are:
    ..
    COMPILER_PATH='/opt/rpi/rpi-gcc-8.3.0/bin'
    ..
    WARNING: Unknown C compiler arm-linux-gnueabihf-gcc, unable to select optimal CFLAGS
    ..
    arm-linux-gnueabihf-gcc -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -funsafe-math-optimizations -lm -mno-apcs-stack-check -mstructure-size-boundary=32 -mno-sched-prolog -E -o /tmp/ffconf.cc8oXqK7/test.o /tmp/ffconf.cc8oXqK7/test.c
    ./configure: 906: ./configure: arm-linux-gnueabihf-gcc: not found
    ..
    C compiler test failed.


    If i run /opt/rpi/rpi-gcc-8.3.0/bin/arm-linux-gnueabihf-gcc then i get "arm-linux-gnueabihf-gcc: fatal error: no input files". So i assume, it is finding the compiler at least.

    I'd appreciate your help.
    Nik

    ReplyDelete
    Replies
    1. This is pretty old stuff. I guess the var was renamed to RPI_COMPILER_PATH: https://github.com/carlonluca/pot/blob/master/piomxtextures_tools/compile_ffmpeg.sh#L32.

      Delete
    2. You are using both versions in the script (RPI_COMPILER_PATH and COMPILER_PATH). It works now.

      I am stuck with two problems:

      1)
      Are the ffmpeg options libsmbclient and libssl really needed? There seem to be missing files on my computer, but i cannot find out libraries to install. Any hints except libsmbclient-dev?

      2)
      I think you changed the folder structure, so that i need to patch your "prepare_openmaxil_backend.sh" (lines 64/65). But how?

      cp -a build-PiOmxTextures/libPiOmxTextures* PiOmxTextures/lib
      => change like this?
      cp -a build-PiOmxTextures/piomxtextures_lib/libPiOmxTextures* PiOmxTextures/lib

      cp -a build-PiOmxTextures/piomxtextures/* PiOmxTextures/include
      => change to what?

      Thanks for your help. I really hope i get it to work. Your pot still seems to be the only option for HW accelerated videos with QT/QML.

      Nik

      Delete
    3. 1) They are only needed if you use protocols needing smb or ssl. Should not be needed for local files. I'm sorry, I don't remember the names of all the deps, probably also libssl-dev, libcrypto etc... but not sure, you should probably refer to ffmpeg docs.
      2) Are you sure prepare_openmaxil_backend.sh is even needed? According to https://thebugfreeblog.blogspot.com/p/build-procedure-for-piomxtextures.html it seems that is part of the old build procedure. ./prepare_3rdparty.sh seems to be the only one needed before building the plugin itself.

      Delete
  13. 1) OK, thanks
    2) OK, i repeated all steps and POT now seems to compile.
    But make-install installs nothing. Would you have a hint?

    Details:
    - qmake writes only one line:
    Info: creating stash file /home/niki/piview-dev/opt_qt_for_rpi/qt5.15.2/qtsrc/pot-5.7.3/.qmake.stash

    - make seems to run without errors, only some warnings about code

    - make-install writes "nothing to be done for 'install'" for each folder, e.g.:

    ReplyDelete
    Replies
    1. I do not think there is any install target. Once make is done, the library is ready. Put it manually in your Qt installation.

      Delete
    2. ok, are you sure?
      Your manual tells different: "If you're interested in the Qt plugin, once built, you should have the new openmaxil plugin in your Qt install dir".

      Which files should i copy on the RPI to my /usr/local/qt5pi folder?

      There are several pot folders that contain *.so files, e.g.
      pot-5.7.3/3rdparty/ffmpeg/ffmpeg_pi2/lib/
      pot-5.7.3/piomxtextures_lib
      pot-5.7.3/piomxtextures_qt_driver/mediaplayer/
      pot-5.7.3/piomxtextures_src/omxplayer_lib/

      Delete
    3. Mmh... not so much now... :-)
      However, simply look for the library. I don't remember where, but I'd go under piomxtextures_qt_driver, as it is a Qt driver.

      Delete
    4. Finally done, the simple-video works :-)
      I had to copy files from the following folder:
      - 3rdparty/ffmpeg/ffmpeg_pi2/lib/
      - piomxtextures_qt_driver/mediaplayer/

      Delete
  14. I cannot post the log of make-install. It seems like the blog-software doesn't allow it.

    ReplyDelete
    Replies
    1. You can use any pastebin servive: https://luc4.duckdns.org/pb/

      Delete
  15. Hi Luca! Is this compiler compatible with Raspberry Pi Model B Plus Rev 1.2 ? Because I have illegal instruction exception with this... Thank you!

    ReplyDelete
    Replies
    1. Hello. Nope sorry, this is only compatible with armv6.

      Delete
    2. Thank you! But I think you want to write armv7+... armv6zk is pi1 :)

      Delete
    3. You said "Raspberry Pi Model B", so I thought 1.2 was still version 1 based on armv6. If it is a rpi2 based on armv7 then I can't say no, cause I don't think I ever tried this toolchain for armv7. I built it specifically for armv8, but I never tried to target armv7. However, if you tried to specify the arch and cpu and it still builds v8 binaries, then I guess it is not supported, sorry.
      Version 6.3 instead seems to be for armv7-a. It may work anyway.

      Delete
    4. I am confused :) so my rpi is from 2014 and needs a compiler --with-arch=armv6zk! Your gcc-8.3.0 is with armv8-a and therefore the illegal instruction problem. But when I built one compiler based on crosstool-ng with the correct arch I ran into problems about -sysroot and the qt compilation stopped because there was missing libraries.
      Your gcc-8.3.0 compiled the qt libraries without any problem but because of the armv8-a the illegal instruction exception occurred.
      Finally my question is how did you build your compiler ? Can you share your build script/command line... with which you built the 8.3 compiler so I can compile --with-arch=armv6zk?
      Thank you!

      Delete
    5. Ok! I solved it...thanks to your compiler verbose output :) I found out that I needed to add include path and lib path to the whole configure command line! Thanks again!

      Delete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Hi Luca, i'm using your GCC with QT 5.15.1 and works like a charm.
    I'd like to make my own GCC (maybe >8.3.0)... do you have a tutorial how to make it?
    Thank you

    ReplyDelete
    Replies
    1. Hello, no sorry, I don't have such a tutorial.
      Regards.

      Delete