c++ – Cross-compiling a C ++ application with Qt from Linux on Windows

Question:

Hello! I am a beginner programmer and recently using Qt. Can't figure out how to compile a C ++ application using Qt. I wrote the simplest program for Linux Mint:

#include <QtGui>
#include <QWidget>
#include <QTimer>
#include <QPoint>


int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    return app.exec();
}

want to get the .exe. To do this, I try to follow the instructions from here:

https://askubuntu.com/a/656329

As I understand it, there is one missing step. I am doing this:

PATH=<mxe root>:$PATH
export PATH
<mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5 -project

Here I am getting an error

Project ERROR: Cannot run compiler 'i686-w64-mingw32.static-g++'. Maybe you forgot to setup the environment?

But I ignore her and continue:

<mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5
make

At the same time, you cannot immediately run qmake without -project, it gives me a help. But after make, I get an error:

make[1]: i686-w64-mingw32.static-g++: Command not found

I figured it out with her. It is necessary to replace the lines in Makefile.Release

CXX         = i686-w64-mingw32.static-g++
LINKER      = i686-w64-mingw32.static-g++

on

CXX         = <mxe root>/usr/bin/i686-w64-mingw32.static-g++
LINKER      = <mxe root>/usr/bin/i686-w64-mingw32.static-g++

But now an error appears that I already cannot overcome:

fatal error: QWidget: No such file or directory

Can you please tell me what to do. And, if possible, explain why the line was also omitted from that answer

<mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5 -project

and I have to do such strange manipulations. I suspect that I may have some completely idiotic mistakes. And there is another problem that I do not understand which versions of Qt are used in which step. It so happened that I installed myself both the fourth and fifth Qt. But, as I understand it, the question is about the fifth Qt.

Answer:

You need to do this:

0) As stated in the answer https://askubuntu.com/a/656329 , you need to:

git clone https://github.com/mxe/mxe.git
cd mxe && make qtbase

1) Add a line to the source

#include <QtWidgets>

2) Then

PATH=<mxe root>:$PATH
export PATH
<mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5 -project
<mxe root>/usr/bin/i686-w64-mingw32.static-qmake-qt5

ignoring the error that appears after /usr/bin/i686-w64-mingw32.static-qmake-qt5 -project

3) Then add the line to the test.pro file

QT += widgets

after the line INCLUDEPATH + =.

4) Execute

make

It will fail, but it is not the end.

5) Replace in Makefile.Release

CXX = i686-w64-mingw32.static-g++
LINKER  = i686-w64-mingw32.static-g++

on

CXX = <mxe root>/usr/bin/i686-w64-mingw32.static-g++
LINKER  = <mxe root>/usr/bin/i686-w64-mingw32.static-g++

6) Execute again

make

And test.exe is generated in the release folder


If I add the lines to my C ++ file

QWidget w;
w.show();

then after similar manipulations the window appears, I checked it under a virtual machine with a 64-bit eighth Windows.

Scroll to Top