How to integrate mkspec into a cross-compilation SDK
-
Hello.
In order to prepare an SDK that includes qt tools (qmake, moc, rcc, uic), what would the correct process be?
Here is what I have, and but experience problems with qmake finding thespec_pre.prf, etc.STAGE I
I have prepared an SDK using crosstool-ng, which could be extracted to different folders. The structure of the SDK content is:/path/to/sdk/ toolchain/bin i686-xyz-g++ (and other compilers/binutils) sysroot (headers and libraries from root filesystem on the target) usr/include usr/libSTAGE II
I add a mkspeclinux-MYDEVICE-g++under Qt sourcesqtbase/mkspecs/devices. What variables shall I set in this mkspec?CROSS_COMPILE QMAKE_CC, QMAKE_CXX, ... (compiler, linker, ar, ) QMAKE_CFLAGS, QMAKE_CXXFLAGS => --sysroot=/path/to/sdk/sysrootShould I change other variables like
QMAKE_INCDIR, QT_SYSROOT, QT_HOST_*, etc?STAGE III
I "configure" and cross-compile qtbase with this spec. What should I setextprefix, hostprefixso that it will cross-compile Qt for my target, but also work within the SDK with relative paths?cd /path/to/build /path/to/qt/source/configure -device linux-MYDEVICE-G++ ... -prefix /usr -extprefix /???/sysroot/usr -hostprefix /???/toolchain make make INSTALL_ROOT=/path/to/install installSTAGE IV
Copy Qt host tools (qmake, moc, rcc, uic) from/path/to/installto, for example,/path/to/sdk/toolchain/bin/qt5/under SDK toolchain. Is the path important here due to the qmake configuration?Copy Qt mkspecs from
/path/to/installto, for example,/path/to/sdk/toolchain/. Is the path important here? Should I update variables to avoid absolute paths for sysroot, etc?STAGE V
Build a sample project. How do I tell qmake where to find the correct mkspec? I think, some variables are built in the qmake executable and cannot be overridden by environment variables, and some can be overridden with environment variables?cd /path/to/example/build export PATH=/path/to/sdk/toolchain/bin # export QMAKE_SPEC ??? /path/to/sdk/toolchain/bin/qt5/qmake -spec linux-MYDEVICE-g++ /path/to/example/source/example.pro make -
It turns out using
qt.confunder the same directory asqmakesolves the problem.
It can be used to set the paths properly within the cross-compilation toolchain: Using qt.conf -
Hello.
In order to prepare an SDK that includes qt tools (qmake, moc, rcc, uic), what would the correct process be?
Here is what I have, and but experience problems with qmake finding thespec_pre.prf, etc.STAGE I
I have prepared an SDK using crosstool-ng, which could be extracted to different folders. The structure of the SDK content is:/path/to/sdk/ toolchain/bin i686-xyz-g++ (and other compilers/binutils) sysroot (headers and libraries from root filesystem on the target) usr/include usr/libSTAGE II
I add a mkspeclinux-MYDEVICE-g++under Qt sourcesqtbase/mkspecs/devices. What variables shall I set in this mkspec?CROSS_COMPILE QMAKE_CC, QMAKE_CXX, ... (compiler, linker, ar, ) QMAKE_CFLAGS, QMAKE_CXXFLAGS => --sysroot=/path/to/sdk/sysrootShould I change other variables like
QMAKE_INCDIR, QT_SYSROOT, QT_HOST_*, etc?STAGE III
I "configure" and cross-compile qtbase with this spec. What should I setextprefix, hostprefixso that it will cross-compile Qt for my target, but also work within the SDK with relative paths?cd /path/to/build /path/to/qt/source/configure -device linux-MYDEVICE-G++ ... -prefix /usr -extprefix /???/sysroot/usr -hostprefix /???/toolchain make make INSTALL_ROOT=/path/to/install installSTAGE IV
Copy Qt host tools (qmake, moc, rcc, uic) from/path/to/installto, for example,/path/to/sdk/toolchain/bin/qt5/under SDK toolchain. Is the path important here due to the qmake configuration?Copy Qt mkspecs from
/path/to/installto, for example,/path/to/sdk/toolchain/. Is the path important here? Should I update variables to avoid absolute paths for sysroot, etc?STAGE V
Build a sample project. How do I tell qmake where to find the correct mkspec? I think, some variables are built in the qmake executable and cannot be overridden by environment variables, and some can be overridden with environment variables?cd /path/to/example/build export PATH=/path/to/sdk/toolchain/bin # export QMAKE_SPEC ??? /path/to/sdk/toolchain/bin/qt5/qmake -spec linux-MYDEVICE-g++ /path/to/example/source/example.pro makeAFAIK there is an easier way, when you cross compile Qt on your machine, there you need to setup only the cross-compiled qmake in Qt creator. You can then easily switch between different tool chains (e.g. desktop to enbedded build and back) in creator.
-
Thank you.
My development machine has its own Qt installation, with a different version. So, QtCreator works fine with the default Desktop kit. Changing the qmake to the cross-compiled version will possibly confuse it due to the built-in paths for mkspecs, other host tools, etc.
But in order to cross-compile for the target device, not necessarily on QtCreator, how will I tell the cross-compiled qmake where the correct mkspec and tools (moc, rcc, uic) for the target device is?
- Which environment variables should I provide before running the cross-compiled qmake?
QMAKESPEC? QMAKE_MKSPECS? qmake -spec /path/to/sdk/toolchain/mkspecs/linux-MYDEVICE-g++?- Within
qmake.conf, which variables should I set in addition to the cross compilation set-up? - Do I change
QT_variables from Configuring qmake in the environment orqmake.conf?
-
Thank you.
My development machine has its own Qt installation, with a different version. So, QtCreator works fine with the default Desktop kit. Changing the qmake to the cross-compiled version will possibly confuse it due to the built-in paths for mkspecs, other host tools, etc.
But in order to cross-compile for the target device, not necessarily on QtCreator, how will I tell the cross-compiled qmake where the correct mkspec and tools (moc, rcc, uic) for the target device is?
- Which environment variables should I provide before running the cross-compiled qmake?
QMAKESPEC? QMAKE_MKSPECS? qmake -spec /path/to/sdk/toolchain/mkspecs/linux-MYDEVICE-g++?- Within
qmake.conf, which variables should I set in addition to the cross compilation set-up? - Do I change
QT_variables from Configuring qmake in the environment orqmake.conf?
The idea with Qt is basically that it is compiled for each machine and you may have different Qt versions with separate qmake versions. AFAIK you basically call the qmake for a specific version and all is already set to compile and link. I am not exactly sure about command line, but certainly for creator.
Typically you have an installation like this for windows:
c:\Qt\5.9.1\mingw53_32\bin\qmake.exe c:\Qt\5.9.2\mingw53_32\bin\qmake.exe c:\Qt\5.10.1\mingw53_32\bin\qmake.exeother folders are neglected.
By calling the qmake of 5.10.1 all shall be set for complete compilation. And the same for other installations.I have a Ubuntu desktop with an installed desktop version of Qt. And I have there also the cross-compiled version (for a beagle bone). Both are used in kits by creator and simply by changing the kit, I can do the compilation for either target.
The only open question is if there are environment changes done when switching between different kits. However, thisyou can find out when checking the compile environments within creator.
-
The problem is that absolute paths may leak into the binaries (host tools, or cross-compiled libraries), which is a problem when the SDK is copied to another directory.
Within the
mkspecsdirectory, some paths are used relatively such asinclude(../common/linux.conf), but some paths are set based on value ofextprefixparameter to theconfigurecommand, for example,QMAKE_INCDIR_OPENGL = /path/to/sdk/sysroot/usr/include/libdrminmkspecs/modules/qt_lib_gui_private.pri.So, I am trying to figure out what the best practices would be for:
- setting directory paths in
configureparameters such ashostprefix,extprefix - setting directory paths in
linux-MYDEVICE-g++/qmake.conf - processing directory paths in the
mkspecsgenerated for the host development system likeqt_lib_gui_private.pri - settings environment variables for running
qmakeon the host development system command line to use the correct mkspec and host tools (moc, rcc, uic)
- setting directory paths in
-
The problem is that absolute paths may leak into the binaries (host tools, or cross-compiled libraries), which is a problem when the SDK is copied to another directory.
Within the
mkspecsdirectory, some paths are used relatively such asinclude(../common/linux.conf), but some paths are set based on value ofextprefixparameter to theconfigurecommand, for example,QMAKE_INCDIR_OPENGL = /path/to/sdk/sysroot/usr/include/libdrminmkspecs/modules/qt_lib_gui_private.pri.So, I am trying to figure out what the best practices would be for:
- setting directory paths in
configureparameters such ashostprefix,extprefix - setting directory paths in
linux-MYDEVICE-g++/qmake.conf - processing directory paths in the
mkspecsgenerated for the host development system likeqt_lib_gui_private.pri - settings environment variables for running
qmakeon the host development system command line to use the correct mkspec and host tools (moc, rcc, uic)
@fatih.erol said in How to integrate mkspec into a cross-compilation SDK:
The problem is that absolute paths may leak into the binaries (host tools, or cross-compiled libraries), which is a problem when the SDK is copied to another directory.
You are right. That is the reason at least for qmake to be able to work IIRC.
However, the question what is the harm, if there is any for the applciation you generating. It has to work independently from your installation on your desktop. If that is the case I am not worried about having a path somewhere which is not used.Within the
mkspecsdirectory, some paths are used relatively such asinclude(../common/linux.conf), but some paths are set based on value ofextprefixparameter to theconfigurecommand, for example,QMAKE_INCDIR_OPENGL = /path/to/sdk/sysroot/usr/include/libdrminmkspecs/modules/qt_lib_gui_private.pri.So, I am trying to figure out what the best practices would be for:
- setting directory paths in
configureparameters such ashostprefix,extprefix - setting directory paths in
linux-MYDEVICE-g++/qmake.conf - processing directory paths in the
mkspecsgenerated for the host development system likeqt_lib_gui_private.pri - settings environment variables for running
qmakeon the host development system command line to use the correct mkspec and host tools (moc, rcc, uic)
That is outside of my experience. I tend to go for the "official" ways and try to use as much as possible in the main stream of the use. Otherwise fiddling around with all those settings is a typical way to gain a lot of frustration, but no real work done IMHO.
- setting directory paths in
-
Thank you.
Btw, where doesqmakesave its variables, when you runqmake -set XYZto alter them? -
Thank you.
Btw, where doesqmakesave its variables, when you runqmake -set XYZto alter them?AFAIK some are compiled in and others are in the mkspecs conf files.
-
It looks like:
-
some are built in the
qmakeexecutable based on-hostprefix,-hostbindir,-hostdatadir,-hostlibdirarguments toconfigurecommand. I am not sure how exactly they are derived from these variables. Since aqmakeis prepared for buildingqtitself, and whenmake installis run. I am not sure the values of these arguments can be set to paths relative to the qmake path (such as../../path/to/toolchain) in the install directory. -
When
qmake -set VARIABLE VALUEis run, it sets this value in/path/to/sysconfdir/QtProject.conf, according to-sysconfdirargument toconfigurecommand, or${HOME}/.config/QtProject.conf. -
Variables have different values for different environments such as
QT_HOST_DATA,QT_HOST_DATA/dev,QT_HOST_DATA/get,QT_HOST_DATA/src. It looks like/getand/srcare also effective for overriding them withqmake -setfor cross-compilation.
-
-
It turns out using
qt.confunder the same directory asqmakesolves the problem.
It can be used to set the paths properly within the cross-compilation toolchain: Using qt.conf