qtmingw-w64msys2qt5.6

How to use MinGW-64 with Qt Creator


I am aware that there are many post about this, but I honestly didn't understood any of it.

So, how do I install a kit for my Qt Creator (open source 5.7)?

I just want to be able to develop in Qt and chose betwen MinGW 32 and MinGW 64.

Thanks in advance!


EDIT: I also checked the wiki page. Most of the commands didn't worked. And I was told that it is outdated.


Solution

  • I know that your question is how do you install a kit for your Qt Creator, but first I think it's needed an introduction (Sorry for your eyes, English is not my native language)

    Introduction

    The intention is to use the GCC compiler under Windows, which means we need MinGW (Minimalist GNU for Windows).

    MinGW only works for 32 bits, so we need the 64 bits forks, which means to use the MinGW-w64 or TDM-GCC flavors.

    With that we can create our applications/programs in Windows. In addition, we have other two different tools:

    About the binary compatibility chain

    When we make an application, we have to follow the chain of libraries compiled with the same compiler version, the same way we have to follow the application binary interface (32 or 64 bits) for those libraries.

    This means, if we want to compile an application for 32 and 64 bits with MinGW-w64 5.3, plus the Qt 5.7 Framework, we need:

    Now comes the weird thing. At Qt official webpage, it's only the 32bits builds available for MinGW... I don't know why...

    Here is where the Qt64-NG project comes in, a place where to get the Qt Framework 64bits binary packages for MinGW-w64. Unfortunately the project is closed, so they are only available until the Qt 5.5 Framework version.

    I don't know where else to get newer 64bits Qt binary packages for MinGW-w64 (Maybe the ones at MSYS2 project? I haven't tried yet). So, if one needs them, at this moment they must compile them themselves (This is to answer your opensource 5.7 comment).

    Install and configuration

    Now to your question. How to install a kit for your Qt Creator. I'm going to answer for 64bit binaries because it's what I use (and latter you just need to do the same thing for 32bits)

    To use Qt Creator with MinGW-w64, one just needs to:

    That's all, with this we can create 32 and 64 bits applications.

    By other way, in addition to the above steps, if one wants to create applications using the Qt Framework library (a GUI/Interface for our applications), the binary package is needed, the 64 bit one in this case (the 32bit binary package is available at the Qt official page)

    Here is where the installation process ends. In my case, I have all under the same folder:

    D:\Programacion\mingw64_5.3.0rev0\
    D:\Programacion\qt64-ng\qt-5.5.0-x64-mingw510r0-seh\
    

    Now you just need to configure Qt Creator, in this case:

    Tools > Options > C++, Compilers, Add > MinGW

    Tools > Options > C++, Debuggers, Add

    And, if one wants to create 64bits programs using Qt Framework, in addition to the above:

    Tools > Options > C++, Qt versions, Add, and select the qmake.exe placed at the qt64-ng bin directory.

    Now you just need to specify the Kit:

    Tools > Options > C++, Kits, Add

    And in CMake goes the CMake path if one is going to use it (I use it with Ninja).

    Note: To install Ninja, just copy ninja.exe to the mingw-w64\bin directory, and at the Kit, in Cmake generator push change to generator->ninja, and Extra generator->CodeBlocks. Ninja launches several make commands at same time, which decreases compilation times.


    Long text for 1 minute of configuration. The Kit is what we select to compile the project, and one can have as many Kits as they wish (CompilerA x32 + Qt5.x, CompilerB x64 + Qt5.x, CompilerX x64 + Qt4.8, etc, etc).

    Now, before we finish, an important thing. After we create a project (and the project is open), at the Projects selector (Ctrl+5) we have to take care of the Build Environment variables.

    These are the variables that are going to be added at the command which launches our Runs/Builds for testing and debug.

    In PATH we have to put the paths to MinGW-w64 and to Qt64-NG. And in my humble opinion, I recommend to put it in that order because of dll's. Following our example:

    PATH: D:\Programacion\mingw64_5.3.0rev0\bin;D:\Programacion\qt64-ng\qt-5.5.0-x64-mingw510r0-seh\bin;the_other_paths

    At Qt Creator snapshots branch I don't need to check it, it's done automatically


    Most of the C/C++ editors works that way. To install an editor, specify the compiler&debugger path, and specify Build Environment variables for launching from the editor (overriding those environment variables we have in Windows).

    Note: I recommend to compile Qt Creator with 64 bits, due as happen with the Framework, for Windows it's only available in 32 bit at the official Qt website

    Alternative way

    In addition, we have:

    Everything is the same, we just download/install the packages with the pacman command, and the 32 and 64 bit versions are available. Those applications need to be launched from the MSYS2 shell. It's not a binary compatibility thing but paths matter.

    The libraries available at MSYS2 project can be used in the first tool chain I described (due are build under MinGW-w64 also).


    EDIT: Corrected namings, the last explanation, and added Ninja's url and installation note.