12

I'm cross compiling using Qmake and QtCreator. In the settings for the Kits (toolchain and qmake details are set there) there is a field called Sysroot:. (Example here)

Since QtCreator and Qmake are, at the end, responsible for generating a Makefile, my question is, to what does that option translate to in the Makefile and how does it get passed to the toolchain?


Motivation for the question

I have the Sysroot: pointing to ~/path-to-sysroot. ~/path-to-sysroot contains the regular sysroot structure cross compiled for an embedded target.

~/path-to-sysroot
   ├── bin
   ├── include
   ├── lib
   ├── sbin
   ├── share
   └── usr

When I try to cross compile some code which depends on the libraries in ~/path-to-sysroot/usr/lib, it fails with a message that the libs are missing, but the exist there. I have parsed the generated makefile and found no traces of ~/path-to-sysroot/usr/lib.

TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
  • It probably ends up either as a `--sysroot` option to GCC or is compiled directly into the toolchain (so that it does not need to be specified). What error message do you get exactly? Did you manage to trace down the compilation command in the generated makefile, and what does it say if so? (An easy way to debug is to press Ctrl-C during a build from the shell and see where you get the error, if you're on *nix.) – Ulfalizer Apr 08 '15 at 12:20
  • Did you build Qt yourself? I had a lot of headache trying to get Qt to build correctly so we could cross-compile for ARM. Run `qmake --query` and see if the sysroot is correct in the output of that command. Some of the paths are automatically configured for qmake - I suspect that they're hardcoded into qmake as defaults, but they can be overridden (using some other form of the `qmake` command). – Steve Apr 08 '15 at 13:17
  • @Ulfalizer It says that the header file of the library is missing. Ending up as `--sysroot` was something I was hoping to find in the Makefile. Don't see how the setting specified in QtCreator could be compiled into the toolchain. – TheMeaningfulEngineer Apr 08 '15 at 18:37
  • @Alan: Yeah, my guess is that it's passed to GCC, possibly embedded in a makefile variable. Did you manage to track down the compilation command? – Ulfalizer Apr 08 '15 at 18:49
  • @Ulfalizer Yup, it fails on `g++ -o -lmylib`. And libmylib is in `~/path-to-sysroot/usr/lib`. If I manually add `-L~/path-to-sysroot/usr/lib -lmylib` it passes. Which is why I'm guessing the sysroot isn't set correctly. – TheMeaningfulEngineer Apr 08 '15 at 19:09
  • @Alan: Is that a literal "g++"? I would have expected it to use the g++ from the cross-compiler (which would have a name like "arm-angstrom-linux-gnueabi-g++", depending on the platform). – Ulfalizer Apr 08 '15 at 19:12
  • @Ulfalizer Great observation! As if all of my Kit settings from QtCreator are being ignored, that would explain the behaviour exactly. – TheMeaningfulEngineer Apr 08 '15 at 19:26
  • Yeah, prolly some path/cross-compiling setup issue. Kinda odd that it works with the `-L`, since those libraries would have the wrong format for the host platform. – Ulfalizer Apr 08 '15 at 19:29
  • @Ulfalizer "Works" as in "doesn't fail at THAT point. :) Wanted to try and stay on the topic. – TheMeaningfulEngineer Apr 08 '15 at 19:31
  • Yeah, mostly that I would've expected it to not compile/link at all. :) – Ulfalizer Apr 08 '15 at 19:32
  • Pllease, don't use C and C++ tags in a nonlanguage related question. – Luis Colorado Apr 09 '15 at 06:50

1 Answers1

1

from :http://doc.qt.io/qt-5/qt-conf.html

The qt.conf file can be used to override the hard-coded paths that are compiled into the Qt library. These paths are accessible using the QLibraryInfo class. Without qt.conf, the functions in QLibraryInfo return these hard-coded paths; otherwise they return the paths as specified in qt.conf.

Without qt.conf, the Qt libraries will use the hard-coded paths to look for plugins, translations, and so on. These paths may not exist on the target system, or they may not be accessible. Because of this, you may need qt.conf to make the Qt libraries look elsewhere.

qmake -query
QT_SYSROOT:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux
QT_INSTALL_PREFIX:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr
QT_INSTALL_PREFIX/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr
QT_INSTALL_ARCHDATA:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5
QT_INSTALL_ARCHDATA/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5
QT_INSTALL_DATA:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/qt5
QT_INSTALL_DATA/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/qt5
QT_INSTALL_DOCS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/doc/qt5
QT_INSTALL_DOCS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/doc/qt5
QT_INSTALL_HEADERS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/include/qt5
QT_INSTALL_HEADERS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/include/qt5
QT_INSTALL_LIBS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib
QT_INSTALL_LIBS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib
QT_INSTALL_LIBEXECS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/libexec
QT_INSTALL_LIBEXECS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/libexec
QT_INSTALL_BINS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/bin/qt5
QT_INSTALL_BINS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/bin/qt5
QT_INSTALL_TESTS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/qt5/tests
QT_INSTALL_TESTS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/qt5/tests
QT_INSTALL_PLUGINS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/plugins
QT_INSTALL_PLUGINS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/plugins
QT_INSTALL_IMPORTS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/imports
QT_INSTALL_IMPORTS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/imports
QT_INSTALL_QML:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/qml
QT_INSTALL_QML/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5/qml
QT_INSTALL_TRANSLATIONS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/qt5/translations
QT_INSTALL_TRANSLATIONS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/share/qt5/translations
QT_INSTALL_CONFIGURATION:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/etc/qt5
QT_INSTALL_CONFIGURATION/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/etc/qt5
QT_INSTALL_EXAMPLES:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/examples
QT_INSTALL_EXAMPLES/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/examples
QT_INSTALL_DEMOS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/examples
QT_INSTALL_DEMOS/raw:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/examples
QT_HOST_PREFIX:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr
QT_HOST_DATA:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib/qt5
QT_HOST_BINS:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/bin/qt5
QT_HOST_LIBS:/opt/mel/next+snapshot/sysroots/i686-melsdk-linux/usr/lib
QT_EXTERNAL_HOST_BINS:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/usr/bin/qt5
QMAKE_SPEC:/home/mentor/work/git/mel_repos/mel_cedar/build/tmp/sysroots/x86_64-linux/usr/lib/qt5/mkspecs/linux-oe-g++
QMAKE_XSPEC:linux-oe-g++
QMAKE_VERSION:3.0
QT_VERSION:5.4.1

qmake doesnot uses a sysroot argument it has all the paths in it. You can customize qmake by overriding those paths in qt.conf but still it has no path which shows sysroot. And I don't think it has any option to specify sysroot. You have to manually set the sysroot in Compiler flags in qtcreator

theadnangondal
  • 1,546
  • 3
  • 14
  • 28
  • In the end, `qmake` is just a tool for generating the Makefile and once its done, it's possible to go to the correct directory and just run `make`. Meaning that the sysroot path (regardless of the attribute name) is somehow passed to the makefile and in the end to the compiler. That's the answer I'm looking for. – TheMeaningfulEngineer May 20 '15 at 11:38