如何在 Qt Creator 中使用 MinGW-64 [英] How to use MinGW-64 with Qt Creator

查看:124
本文介绍了如何在 Qt Creator 中使用 MinGW-64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于这个的帖子,但老实说我没有理解其中的任何一个.

那么,如何为我的 Qt Creator(开源 5.7)安装工具包?

  • 我已经下载并安装了 MSYS2.... 不知道如何处理它.
  • 我已经下载并安装了 Qt64 - NG.... 不知道接下来要做什么.

我只是希望能够在 Qt 中进行开发并选择了 MinGW 32 和 MinGW 64.

提前致谢!

<小时>

我还检查了维基页面.大多数命令都不起作用.有人告诉我它已经过时了.

解决方案

我知道你的问题是你如何为你的 Qt Creator 安装一个套件,但首先我认为它需要一个介绍(对不起,你的眼睛,英语是不是我的母语)

简介

本意是在Windows下使用GCC编译器,也就是说我们需要MinGW(Minimalist GNU for Windows).

MinGW 只适用于 32 位,所以我们需要 64 位 fork,这意味着使用 MinGW-w64 或 TDM-GCC 风格.

  • MinGW,用于 32 位应用程序的 GCC 编译器.
  • MinGW-w64,适用于 32 位和 64 位应用程序的 GCC 编译器.
  • TDM-GCC,适用于 32 位和 64 位应用程序的 GCC 编译器.

这样我们就可以在 Windows 中创建我们的应用程序/程序.此外,我们还有其他两种不同的工具:

  • Qt 框架库,用于创建具有多平台兼容性的 GUI/界面.
  • Qt Creator,一个 C/C++ 编辑器,带有用于 Qt 框架的附加编辑工具.


关于二进制兼容链

当我们创建一个应用程序时,我们必须遵循使用相同编译器版本编译的库链,就像我们必须遵循这些库的应用程序二进制接口(32 位或 64 位)一样.

这意味着,如果我们要使用 MinGW-w64 5.3 和 Qt 5.7 框架编译 32 位和 64 位应用程序,我们需要:

  • MinGW-w64 5.3(在配置中带有 32 位标志)和在 MinGW-w64 下编译的 Qt 5.7 Framwork 32 位版本(MinGW-w64 5.3 或更低版本,只要它们与我们的编译器保持二进制代码兼容性).
  • MinGW-w64 5.3(在配置中带有 64 位标志)和在 MinGW-w64 下编译的 Qt 5.7 Framwork 64 位构建(MinGW-w64 5.3 或更低版本,只要它们与我们的编译器保持二进制代码兼容性).

现在奇怪的事情来了.在 Qt 官方网页上,它仅适用于 32 位版本的 MinGW ......我不知道为什么......

这里是 Qt64-NG 项目的时候,在这里可以获取用于 MinGW-w64 的 Qt 框架 64 位二进制包.不幸的是,该项目已关闭,因此仅在 Qt 5.5 框架版本之前可用.

我不知道其他地方可以为 MinGW-w64 获得更新的 64 位 Qt 二进制包(也许是 MSYS2 项目中的那些?我还没有尝试过).所以,如果需要,此时必须自己编译(这是为了回答你的开源5.7评论).


安装和配置

现在你的问题.如何为您的 Qt Creator 安装套件.我将回答 64 位二进制文​​件,因为这是我使用的(而后者你只需要为 32 位做同样的事情)

使用 Qt Creator 和 MinGW-w64,只需要:

  • 下载 Qt Creator 并安装它.我的建议是下载 4.1(或更高版本)snapshots 如果要使用 CMake项目.

  • 下载 MinGW-w64(posix-seh 或您选择的风格)+ 解压到一个文件夹中.

就是这样,我们可以创建 32 位和 64 位应用程序.

另外,除了上述步骤之外,如果要使用 Qt Framework 库(我们应用程序的 GUI/界面)创建应用程序,则需要二进制包,这种情况下为 64 位(32 位二进制包可在Qt官方页面获得)

  • 下载 Qt64-NG(posix-seh 或您的上面选择风味)+ 解压到一个文件夹中.
    之后需要执行该目录中包含的qtbinpatcher.exe,只需双击即可.
    注意:如果您将此目录更改为其他路径,再次执行qtbinpatcher.

安装过程到此结束.就我而言,我都在同一个文件夹下.示例:

D:Programacionmingw64_5.3.0rev0D:Programacionqt64-ngqt-5.5.0-x64-mingw510r0-seh

现在你只需要配置QtCreator,在这种情况下:

工具 > 选项 > C++、编译器、添加 > MinGW

  • 名称中输入编译器版本,MinGW-5.3 x64
    这是将在 Kits 中显示的名称
  • 编译器路径中浏览C++编译器路径,在本例中为D:Programacionmingw64_5.3.0rev0ing++.exe

    注意,在ABI 中选择在编译器中使用 64 位标志.这就是我们放入 name x64 的原因.对于 32 位,只需复制并更改选择即可.

工具 > 选项 > C++、调试器、添加

  • Path 中浏览到调试器路径,在本例中为 D:Programacionmingw64_5.3.0rev0ingdb.exe
  • 名称中输入在版本中显示的名称,在本例中为 GDB 7.10.1.
    这是将在 Kits 中显示的名称

而且,如果您想使用 Qt Framework 创建 64 位程序,除了上述:

Tools > Options > C++ , Qt versions, Add,然后选择qt64-ng bin目录下的qmake.exe.

  • 在这种情况下,D:Programacionqt64-ngqt-5.5.0-x64-mingw510r0-sehinqmake.exe
  • 名称中输入Qt %{Qt:Version} (qt-5.5.0-x64-mingw510r0-seh)
    这是名称将显示在 Kits 标签中

现在您只需要指定套件:

工具 > 选项 > C++、工具包、添加

  • 名称 MinGW-5.3 x64 (Qt-5.5)
  • 编译器中选择 MinGW-5.3 x64
  • 调试器中选择 GDB 7.10.1
  • Qt 版本中选择 Qt 5.5.0 (qt-5.5.0-x64-mingw510r0-seh)

并且在 CMake 中,如果有人要使用它,则使用 CMake 路径(我使用它与忍者).

注意:要安装 Ninja,只需将 ninja.exe 复制到 mingw-w64in 目录,然后在 Kit 中,在 Cmake generator 中将更改推送到 generator->ninja 和 Extra generator->CodeBlocks.Ninja 同时启动多个 make 命令,减少编译时间.


1 分钟配置的长文本.Kit是我们编译项目时选择的Kit,可以随心所欲(CompilerA x32 + Qt5.x、CompilerB x64 + Qt5.x、CompilerX x64 + Qt4.8等).

现在,在结束之前,一件重要的事情.创建项目(以及它打开的项目)后,在项目选择器 (Ctrl+5) 中,我们必须处理构建环境变量.

这些是将在启动我们的运行/构建以进行测试和调试的命令中添加的变量.

在 PATH 中,需要将路径放入 MinGW-w64 和 Qt64-NG.根据我的拙见,由于 dll 的原因,我建议按该顺序排列.按照我们的示例:

PATH D:Programacionmingw64_5.3.0rev0in;D:Programacionqt64-ngqt-5.5.0-x64-mingw510r0-sehin;the_other_paths

在 QtCreator 快照分支我不需要检查它,它会自动完成


大多数 C/C++ 编辑器都是这样工作的.要安装编辑器,请指定编译器和调试器路径,并指定从编辑器启动的构建环境变量(覆盖我们在 Windows 中的那些环境变量).

注意:我建议使用 64 位编译 Qt Creator,因为框架会发生这种情况,对于 Windows,它仅在 Qt 官方网站上提供 32 位版本


替代方式

另一方面,我们有:

  • MSYS2,类似 Linux 的工具环境.

都一样,只是我们用 pacman 命令下载/安装软件包,并且有 32 位和 64 位版本.这些应用程序需要从 MSYS2 shell 启动.这不是二进制兼容性,而是路径很重要.

MSYS2 项目中可用的库可以在我描述的第一个工具链中使用(由于也在 MinGW-w64 下构建).


更正了命名、最后的解释,并添加了 Ninja 的 url 和安装说明.

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.

解决方案

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 it's not my native language)

Introduction

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

MinGW only works for 32 bits, so we need the 64 bits forks, what 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 create GUI's/Interfaces with multi-platform compatibility.
  • Qt Creator , an C/C++ editor, with additional editing tools for the Qt Framework.


About the binary compatibility chain

When we make an application, we've to follow the chain of libraries compiled with the same compiler version, the same way we've 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 Framwork 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 Framwork 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 come the weird thing. At Qt official webpage it's only available the 32bits builds for MinGW... I don't know why...

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

I don't know other place where to get newer 64bits Qt binary packages for MinGW-w64 (Maybe the ones at MSYS2 project? I didn't tried yet). So, if one need it, at this moment must be compiled by oneself (This is for answer your opensource 5.7 comment).


Install and configuration

Now 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)

For use Qt Creator with MinGW-w64, one just need:

  • 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 choice flavor) + 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 want to create applications using the Qt Framework library (a GUI/Interface for our applications), it's needed the binary package, this case 64 bit (The 32bit binary package is available at the Qt official page)

  • Download Qt64-NG (posix-seh , or your above choose flavor) + 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 other path, execute again qtbinpatcher.

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

D:Programacionmingw64_5.3.0rev0
D:Programacionqt64-ngqt-5.5.0-x64-mingw510r0-seh

Now you just need to configure QtCreator, 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:Programacionmingw64_5.3.0rev0ing++.exe

    Take note in ABI it's selected to use 64 bits flags in the compiler. That's why we put in name x64. 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:Programacionmingw64_5.3.0rev0ingdb.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 want 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 is, D:Programacionqt64-ngqt-5.5.0-x64-mingw510r0-sehinqmake.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: For install Ninja just copy ninja.exe to the mingw-w64in directory, and at the Kit, in Cmake generator push change to generator->ninja , and Extra generator->CodeBlocks. Ninja launch several make commands at same time, what decreases compilation times.


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

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

Those are the variables that are going to be added at the command who launch our Runs/Builds for testing and debug.

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

PATH D:Programacionmingw64_5.3.0rev0in;D:Programacionqt64-ngqt-5.5.0-x64-mingw510r0-sehin;the_other_paths

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


Most of the C/C++ editors works that way. To install editor, specify compiler&debugger path, and specify Build Environment variables for launch from the editor (overriding those environment variable that we've 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

By other side, we have:

  • MSYS2 , a Linux like tools environment.

There is all the same, just we download/install the packages with the pacman command, and are available the 32 and 64 bit versions. Those applications need to be launched from MSYS2 shell. It's not a binary compatibility thing but a 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.

这篇关于如何在 Qt Creator 中使用 MinGW-64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆