Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QT enable cross-compiling using MinGW (precompiled)
CybeX last edited by
Good day all
I have been searching for a method of cross-compiling for QT-Creator in Linux for sometime now, and I have been having alot of trouble with it.
please note: I am on a Linux machine, and would like to cross compile Windows Apps
- Ubuntu Gnome 16.10
- QT Creator 4.0.2 (based on QT 5.7)
I decided to download precompiled MinGW compilers (i686 and x86_x64 versions) from sourceforge
In QT Creator, adding the compiler is done without an issue, adding the "Kit" and selecting the newly added compiler, an red exclamation gives an error
The Compiler (x86_windows_msys_pe_64bit) cannot produce code for QT version 5.7.0 GCC 64Bit (x86_linux_generic_elf_64bit)
This occurs for both 32 + 64 bit compilers.
koahnig last edited by
Hi and welcome to devnet
Libraries for windows and linux are different. Also when you have a pre-compiled desktop version for linux you cannot use this for an embedded linux. You probably have to compile also Qt libs with your MinGW cross compiler first. Those cross-compiled Qt libs may be combined with any application for are using the same cross-compiler. In your case it Qt creator which is compiled and linked against a special version of Qt libs.
From the error message you are showing you have installed a linux version which could be used for a linux compile on your desktop. The compiled applications may be deployed to any desktop linux.
However, you cannot use those compiled libs for anything else than your desktop and the compiler you have chosen.
CybeX last edited by
@koahnig thank you for the welcome and the response.
To clarify, I need to "recompile" QT sources/libs for QTCreator using the QTCreator-MinGW or using my downloaded precompiled MinGW compiler?
aka ( I not only need the compiler allowing for cross-compiling, but also the libs for the "Windows compiler" )
I am familiar with the compiler, how should I proceed with compiling and adding the libs for the "Windows compiler"
What I am thinking is pulling the source for the Windows MinGW, but adding the libs to a current version of QT-Creator (my current Linux version) I think i will need some guidance / assistance with.
Thank you in advance
koahnig last edited by
You cannot mix libs compiled for different platform or with different compilers in general.
You can directly install Qt creator and the Qt libs already precomiled for linux. Alternatively you can precompiled versions for other OS. However, native comilers can compile always only for the OS they "designed" for.
As you already understand you need a cross-compiler on linux for generation of an executable to be run on windows. Probably if all would be only one file, you simply no longer think about it. You generate hundreds of different .obj using the cross-compiler and link them together. However, you would always use the cross-compiler for generation of those objs when you plan to use this on windows.
Now libs and dynamic libs are basically nothing else than a bunch of packed and special formatted obj-files. Therefore, it is a good idea to use the same compiler thorughout the same process.
You use a native linux gcc for instance. It comes already with some basic libs, you do not have to take of of. With this you can compile any source, create libs adn daynamic libs and finally applications. At the end you have an application executable on linux.
Staying on linux, but you plan to create something for an embedded linux. You take a cross-compiler and do the same thing for your whole source which is not supplied with the embedded compiler. At the end you have an application for embedded linux. At no point you should use something already compiled for your original linux you are working on. Everything shall be specifically compiled for your target.
If you substitute "embedded linux" with any other OS in the paragraph before, it becomes clear that you need to compile everything from source and you are only able to use only libs already supplied with your cross-compiler.
Qt creator is an application using some dynamic Qt libs. Therefore, for whatever platform you are compiling Qt creator you have to make sure that you have libraries fitting with your compiler and the target platform.
Theoretically there is a slight chance that objs and libs compiled on windows with the MinGW on windows are identical with the objs and libs generated with your MinGW cross-compiler on linux. But for sure, I would not bet on this a penny.
Therefore, my advices. Compile the whole Qt libs with your MinGW cross-compiler and as next step Qt creator with the same cross-compiler.
The way I typically handle this is to have a virtual machine (virtualbox is easy and free for linux) with the target environment so I can build. In your case windows. Then just set up mingw or Qt Creator or Visual Studio and Qt. Build there for your windows based deployments.
You definitely can not mix libraries and objects from a different platform (i.e. windows) on your linux host platform.
I can only second what @ambershark says.
Using a virtual machine is far less pain than what you are trying.