How to use MinGW-64 with Qt Creator
Asked Answered
P

3

28

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 already downloaded and installed MSYS2.... don't know what to do with it.
  • I already downloaded and installed Qt64 - NG.... no clue what to do next.

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.

Paragon answered 12/7, 2016 at 17:27 Comment(0)
R
44

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.

  • MinGW, GCC compiler for 32bits applications.
  • MinGW-w64, GCC compiler for 32 and 64 bits applications.
  • TDM-GCC, GCC compiler for 32 and 64 bits applications.

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

  • Qt Framework library, for creating GUI's/Interfaces with multi-platform compatibility.
  • Qt Creator, a C/C++ editor, with additional editing tools for the Qt Framework.

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:

  • MinGW-w64 5.3 (with flags 32 bits in the config) and the Qt 5.7 Framework 32 bits build compiled under MinGW-w64 (MinGW-w64 version 5.3 or lower as long as they maintain binary code compatibility with our compiler).
  • MinGW-w64 5.3 (with flags 64 bits in the config) and the Qt 5.7 Framework 64 bits build compiled under MinGW-w64 (MinGW-w64 version 5.3 or lower as long as they maintain binary code compatibility with our compiler).

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:

  • Download Qt Creator and install it. My advice is to download the 4.1 (or upper version) snapshots if one is going to use CMake projects.

  • Download MinGW-w64 (posix-seh, or your flavor or choice) + decompress in one folder.

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)

  • Download Qt64-NG (posix-seh, or your flavor of choice from above) + decompress in one folder.
    After that it's needed to execute the qtbinpatcher.exe included in that directory, just a double click.
    Note: If you change this directory to a different path, run qtbinpatcher again.

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

  • In name put the compiler version, MinGW-5.3 x64
    It's the name that will be shown in Kits
  • In Compiler path browse for the C++ compiler path, in this case D:\Programacion\mingw64_5.3.0rev0\bin\g++.exe

    Take note: in ABI it's selected to use 64 bits flags in the compiler. That's why we put x64 in name. For 32 bits, just duplicate and change the selection.

Tools > Options > C++, Debuggers, Add

  • In Path browse to the debugger path, in this case D:\Programacion\mingw64_5.3.0rev0\bin\gdb.exe
  • In name put the name showed at version, GDB 7.10.1 in this case.
    It's the name that will be shown in Kits

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.

  • In this case it is D:\Programacion\qt64-ng\qt-5.5.0-x64-mingw510r0-seh\bin\qmake.exe
  • In name put Qt %{Qt:Version} (qt-5.5.0-x64-mingw510r0-seh)
    It's the name that will be shown in Kits tab

Now you just need to specify the Kit:

Tools > Options > C++, Kits, Add

  • In name: MinGW-5.3 x64 (Qt-5.5)
  • In compiler select MinGW-5.3 x64
  • In debugger select GDB 7.10.1
  • In Qt Version select Qt 5.5.0 (qt-5.5.0-x64-mingw510r0-seh)

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:

  • MSYS2, a Linux-like tools environment.

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.

Reynold answered 23/7, 2016 at 23:0 Comment(1)
+1 for citing that only i686-w64-mingw32 tool chain is packaged with Qt Creator (and you don't know why). I just spent a week trying to get what compiled fine in Cygwin working under Qt Creator and the cause is that Cygwin was using the x86_64-w64-mingw32 tool chain. (My issue was my vendors library isn't i686 tool chain compatible, so no linkage!)Doublejointed
B
6

You should decide if you are going to use the MSYS2 ecosystem or not. If you want to use MSYS2, you should uninstall the Qt software that you downloaded separately to avoid confusion. For the rest of this answer, I'll assume you are using MSYS2.

You can install these MSYS2 packages using pacman:

  • mingw-w64-i686-qt
  • mingw-w64-i686-qt-creator
  • mingw-w64-x86_64-qt
  • mingw-w64-x86_64-qt-creator

Then open up a MinGW-w64 32-bit or 64-bit shell using the appropriate shortcut in your Start Menu, and run "qtcreator" at the command line.

You can also use other build systems to build your software. I have used CMake successfully for building Qt applications in MSYS2, instead of Qt Creator.

Buford answered 12/7, 2016 at 19:51 Comment(9)
Thanks for the comment. I just found out that MSYS2 and Qt are two diferent things. Lets say I prefer using the Qt. Is there a way I can install a MinGW 64 on it?Paragon
I thought the official distribution of Qt creator for Windows came bundled with its own MinGW-w64 compiler. You should just try to use that, right?Buford
It comes with a MinGW - 32 compiler and a lot of MSVC kits but thats pretty much it. Also, I tried to run the executable in a 64 bits machine and it didn't worked.Paragon
I am going to close this question because I just found out this ain't even the problem in the first place :/ Still, thanks for taking your time in answering this ^^Paragon
Thanks, this is infinitely easier than trying to upgrade compiler for Qt Creator installed directlyTow
Which one should I install and what is the difference between these two ones? i.imgur.com/Sg1GUAC.pngLemnos
Install the static one if you want to make statically linked programs that have all the Qt code in them instead of depending on Qt DLLs.Buford
In the past Qt supplied a Win32 environment which was based on the original Mingw project. Recently (not sure exactly how long ago Qt 5.11 to 5.12-ish I think) they started to include both Win32 and Win64 environments which are based on the fork that is known as Mingw-64. This will provide what will appears in your Start menu (under "Qt") as various "Qt 5.xx (MinGW {5|7}.yy {32|64}-bit" shells - which are 'bash' command line environments.Unsuspected
However for compiling some things (libraries that your project might need) you require a more POSIX (unix like) environment that will support the autotools suite of things - and Qt does not bundle a "Qt 5xx (MSYS2)" shell which is what you will probably need to support them. So - you may need to go the other way, do NOT install Qt from Qt, instead install MSYS2 and then install the Qt libraries (and the QtCreator IDE) that they (Mingw64) have packaged - and that will also come with a large number of libraries and compilers (GCC etc.) which you may also need.Unsuspected
L
1

Directly launching from explorer will also work, unless you need to use qtcreator's Autotools plugin in which case launching it from an msys2 shell is necessary (so that various environment variables are set correctly).

Lefevre answered 13/7, 2016 at 5:28 Comment(3)
"Directly launching from explorer will also work". What do you mean?Paragon
Double clicking on qtcreator.exe is what I mean rather than using an msys2 shell.Lefevre
@RayDonnelly You can launch qt creator that way, but all the paths that msys2 sets up are important for cmake etc. If you setup your cmake build via the shell then just open it with qtcreator, you could get away with that.Graminivorous

© 2022 - 2024 — McMap. All rights reserved.