Search code examples
c++visual-studioqt

Adding MSVC 2017 to Qt


I want to add the MSVC 2017 compiler correctly inside my Qt 5.13. I know where to add it, but, I don't know how to do it. What should be filled in inside the "add compiler" menu?

My main problem is this: "module machine type 'x64' conflicts with target machine 'x86'", which appears in the console when I build the Qt application. Some of the things that I have tried:

  • Tried to build from Qt Creator and from the Console.
  • Tried all the compilers that are auto-detected by Qt. There are more, but there's no need to mention the rest.

On my default kits, most of the names were in this order: "Qt 5.13.0 for UWP 64/86-bits (MSVC 2017)". I thought that it must be MSVC 2017, so I tried to setup MSVC 2017 (I have MSVC 2019). I found the compiler's main program which is "cl.exe". I went to Qt's auto-detected compilers and I did not find it! I tried to add it by copying the commands for qmake.exe and jom.exe from another kits that were already there. However, I set the compiler's type to 'custom', because I did not find MSVC. Is that wrong, and how does that differ from the other types?

The next thing I tried to fix is this:

Image

The picture above contains the compiler's path and Make's path. I need to find the Make path tool. I think it is required, isn't it? I tried to run the program without the Make step, using only the qmake step. Which led to another problem when running the program: "An Error has occurred when trying to Build/Deploy your program". I set the compiler's path correctly, but I don't know how to set the make path. I don't even know what the make path is. Note that Qt is not giving me any result, because the make path is not set correctly!


Solution

  • You cannot add MSVC manually to Qt Creator. You do need to have it auto-detected.

    Also the mechanisms of detection change depending on MSVC version and Qt Creator version. So be sure to use the latest version of Qt Creator (4.9.2 at this time) to make sure all your installed MSVC toolchains are detected.

    Also given your comment you seem to confuse 64-bit and 32-bit.

    x86 means 32-bit and amd64 means 64-bit.

    This gives:

    • x86 32-bit compiler that produces 32-bit executables
    • x86_amd64 32-bit compiler that produces 64-bit executables
    • amd64 64-bit compiler that produces 64-bit executables
    • amd_x86 64-bit compiler that produces 32-bit executables

    So if you want to produce 32-bit programs, you can use x86 or amd64_x86. If you want to produce 64-bit programs, you can use amd64 or x86_amd64.

    If at some point you want to compile a Qt program, but Qt Creator does not recognize your MSVC toolchain, you still have a solution:

    1. Open Qt 5.12.4 (MSVC 2017 64-bit) from the start menu
    2. In the prompt run C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat amd64
    3. Run qmake