Important: Please read the Qt Code of Conduct -

Cannot build with cmake, qtcreator and MSVC 2019

  • Hello,

    I just wanted to try the new QtCreator cmake support; I have Visual Studio 2019 installed with its C++ compiler.
    I am testing with the latest tools (Windows 10, Qt 5.15.1, VS 2019 16.7.6, Qt creator 4.13.2).
    However, I am not able to build a freshly created "Qt widgets application" project.

    CMake is well detected (initially QtCreator wanted to use by default an old version of CMake installed on my system and crashed: but why ??).
    My Qt kit seems to be okay, but I don't manage to find a working CMake generator.
    I chose Visual Studio 16 2019 and build the project, I have the following error message :
    MSBUILD : error MSB1009: Le fichier projet n'existe pas. (the project file doesn't exists)
    Commutateur : all.vcxproj

    If I just execute CMake, a build directory is created with "ALL_BUILD.vcxproj" and "untitled5.vcxproj" files, but no "all.vcxproj" file...

    I don't know which generator should work on my system (none work for now), and why the "visual studio 2019" generator doesn't work...
    Please help!


  • You should show us your CMakeLists.txt file... is there a top-level project defined?

  • cmake_minimum_required(VERSION 3.5)
    project(test_c_make LANGUAGES CXX)
    # QtCreator supports the following variables for Android, which are identical to qmake Android variables.
    # Check for more information.
    # They need to be set before the find_package(Qt5 ...) call.
    #    if (ANDROID_ABI STREQUAL "armeabi-v7a")
    #        set(ANDROID_EXTRA_LIBS
    #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/
    #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/
    #    endif()
    find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
      add_library(test_c_make SHARED
    target_link_libraries(test_c_make PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

  • Lifetime Qt Champion


    How old were these versions of CMake ?
    Do they appear in your PATH ?

  • I still have another CMake installation in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin
    It is 32 bits version 3.17 (very close to the 34bits, 3.18 version shipped with QtCreator).
    In fact I don't have this entry in the PATH environment variable window of Windows. But I have it in QtCreator in the project view...
    This CMake installation is not even listed in tools > options > kits > CMake.

  • The microsoft CMake doesn't seem to be called.
    If I run CMake manually from the Qt console, I have the same error:

    "C:\Qt\Tools\CMake_64\bin\cmake.exe" --build . --target all
    MSBUILD : error MSB1009: Project file does not exist
    Commutateur : all.vcxproj

    However, if I change the target it succeeds:

    "C:\Qt\Tools\CMake_64\bin\cmake.exe" --build . --target ALL_BUILD

    So, if I go to project tab > build > ALL_BUILD, it compiles fine.
    I also managed to make Ninja build work. Fine!

    I don't know CMake enough: is ALL_BUILD a standard target ?
    I am using a QtCreator generated CMakeLists.txt.

  • IIRC ALL_BUILD is a standard target when you create a solution from cmake. Now, did you produced NMake makefiles ? Because I don't see any Release/Debug switch (default is Debug IIRC).
    Since the --target comes after the . in the call, it is directly forwarded to the actual build engine, and therefore must be a target, hence the search for all.vcxproj. From the command-line, if you want to build everything, just call cmake --build ., the default behaviour is to build everything.

  • With "Visual Studio 16 2019" generator, QtCreator tries to use the all target by default (which doesn't exists) instead of ALL_BUILD.
    With "Ninja" generator, QtCreator uses the all target by default which is OK.
    When in debug mode, QtCreator doesn't use a Release/Debug switch (but doesn't need to...).

    In my opinion, QtCreator shouldn't propose the all target with "Visual Studio 16 2019" generator, since it doesn't exists

  • I installed other Visual C++ extensions from Visual Studio installer (MFC & memory sanitizer), and I cannot build with CMake again.

    Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S C:/dev/untitled3 -B C:/Users/Nicolas/AppData/Local/Temp/QtCreator-VjKhJz/qtc-cmake-hherMDxz in C:\Users\Nicolas\AppData\Local\Temp\QtCreator-VjKhJz\qtc-cmake-hherMDxz.
    -- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18363.
    CMake Error at CMakeLists.txt:3 (project):
      Failed to run MSBuild command:
        C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
      to get the value of VCTargetsPath:
        Microsoft (R) Build Engine version 16.7.0+b89cb5fde pour .NET Framework
        Copyright (C) Microsoft Corporation. Tous droits réservés.
        La génération a démarré 30/10/2020 00:41:15.
        Projet "C:\Users\Nicolas\AppData\Local\Temp\QtCreator-VjKhJz\qtc-cmake-hherMDxz\CMakeFiles\3.18.3\VCTargetsPath.vcxproj" sur le noud 1 (cibles par défaut).
        C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3293,5): error MSB4184: impossible d'évaluer l'expression "[System.IO.Path]::Combine(obj\<unsupported>\Debug\, .NETFramework,Version=v4.0.AssemblyAttributes.cpp)". Caractères non conformes dans le chemin d'accès. [C:\Users\Nicolas\AppData\Local\Temp\QtCreator-VjKhJz\qtc-cmake-hherMDxz\CMakeFiles\3.18.3\VCTargetsPath.vcxproj]
        Génération du projet "C:\Users\Nicolas\AppData\Local\Temp\QtCreator-VjKhJz\qtc-cmake-hherMDxz\CMakeFiles\3.18.3\VCTargetsPath.vcxproj" terminée (cibles par défaut) -- ÉCHEC.
        ÉCHEC de la build.
        "C:\Users\Nicolas\AppData\Local\Temp\QtCreator-VjKhJz\qtc-cmake-hherMDxz\CMakeFiles\3.18.3\VCTargetsPath.vcxproj" (cible par défaut) (1) ->
          C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3293,5): error MSB4184: impossible d'évaluer l'expression "[System.IO.Path]::Combine(obj\<unsupported>\Debug\, .NETFramework,Version=v4.0.AssemblyAttributes.cpp)". Caractères non conformes dans le chemin d'accès. [C:\Users\Nicolas\AppData\Local\Temp\QtCreator-VjKhJz\qtc-cmake-hherMDxz\CMakeFiles\3.18.3\VCTargetsPath.vcxproj]
            0 Avertissement(s)
            1 Erreur(s)
        Temps écoulé 00:00:00.08
      Exit code: 1
    -- Configuring incomplete, errors occurred!
    See also "C:/Users/Nicolas/AppData/Local/Temp/QtCreator-VjKhJz/qtc-cmake-hherMDxz/CMakeFiles/CMakeOutput.log".
    CMake process exited with exit code 1.
    Elapsed time: 00:00.

    impossible d'évaluer l'expression "[System.IO.Path]::Combine(obj<unsupported>\Debug, .NETFramework,Version=v4.0.AssemblyAttributes.cpp)". Caractères non conformes dans le chemin d'accès.
    = cannot evaluate expression XXX. Invalid caracters in the access path.

    It seems that command line encoding errors prevents the build to succeed.
    I see no difference wether I check "Force UTF-8 MSVC compiler output".

  • Okay, found it.

    The error is with the "<unsupported>" keyword that should not be here.
    In tools > options > Kits > Desktop Qt XXX > CMake Generator > Platform & Toolset, the string "<unsupported>" has appeared.
    These fields should be cleared.
    These fields content has been automatically copied to : project tab > CMake > Initial CMake parameters ; fields -A<unsupported> and -T<unsupported> that should be removed.
    Once the fields are cleared, I have to do :

    • Compile > Clear CMake configuration
    • Compile > Execute CMake
    • Build All Projects
    • If a build error happens (non existing project file or target) : project tab > build steps > build > targets > choose the right target
    • Build All Projects

    Then it works, with encoding errors but it builds normally! (enjoy)

    I opened new tickets in the Qt bug tracker :

Log in to reply