What would be a pratical example of sysroot and prefix options for Qt What would be a pratical example of sysroot and prefix options for Qt linux linux

What would be a pratical example of sysroot and prefix options for Qt


These are options that are used when building embedded platforms.Yes they are a royal mess. So here's only a partial answer:

-prefix

  • tried and proven way to say /usr/lib instead of /usr/local/lib or similar for the entire installation of Qt
  • when Qt is built for the platform it is currently running on (typical for desktop)

-sysroot /path

  • intends to build Qt for a system which isn't installed at /
  • for example -sysroot ~/mysystem where ~/myssytem contains/lib /bin etc...
  • will pass --sysroot to other tools, like gcc and pkg-config, so they will search for their dependencies in ~/mysystem/lib rather than /lib

-extprefix /b

  • when using -sysroot /a, don't actually write to /a
  • write qt to /b instead
  • this is intended for cross-compiling against read-only sysroots

-no-gcc-sysroot

  • very specific hack for compilers that can't find their own crt inside --sysroot
  • passes sysroot to pkgconfig and others, but not to gcc
  • so that gcc will be called with -L/sysroot/lib/ correctly, but doesn't try to find implicit paths (crt) here.

-hostprefix /path

  • when compiling for a different target than we are currently running on
  • qmake will be the host architecture (for example x86) and qt itself will be the target architecture (lets say arm)
  • so put qmake in /path instead of the target system specified by -sysroot. it won't be any useful on the target system

To add to the confusion:

-R /path

  • sets the linkers runpath - which is where QtGui finds QtCore for example - independant of all the other options

Which flags you want to use when compiling for a target not your host, depends on a boatload of hardcoded assumptions inside configure.

generally -sysroot plus -prefix should work for most use cases.

i.e. when you have:

 $ ls ~/mytarget lib bin share dev

you could just use -sysroot ~/mytarget -prefix /


One practical example would be cross compiling Qt for Raspberry Pi and then creating a "sister" kit to add to Qt Creator.

The following command install Qt on the Pi after mounting the Pi's root filesystem:

    ./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=$RPI_TOOLCHAIN -sysroot $RPI_SYSROOT -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /usr/local/qt-5.5.1-pi -skip qtwebkit

The following command then installs the binaries on the desktop by using Pi's root file system.

    ./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=$RPI_TOOLCHAIN -sysroot $RPI_SYSROOT -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -extprefix /usr/local/qt-5.5.1-pi -skip qtwebkit

Note that the only difference is the use of -extprefix instead of -prefix which directs the installation location.

Note: You can install Qt on host and target simultaneously by specifying both prefix and extprefix in the same line

Now you can add this kit to your Qt Creator by specifying your qmake path, device, compiler, debugger and sysroot. So you can create a qt project on your desktop and then build and run on either the desktop or the pi depending on the kit you choose.