Flutter error: No CMAKE_CXX_COMPILER could be found

Flutter error: No CMAKE_CXX_COMPILER could be found

我是 Flutter 新手。当我想在 Windows 上 运行 我的 Flutter 应用程序时,我收到此错误:

Launching lib\main.dart on Windows in debug mode...
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.



Building Windows application...
Exception: Unable to generate build files

这是 flutter doctor -v 的输出:

[√] Flutter (Channel stable, 2.10.4, on Microsoft Windows [Version 10.0.19043.1586], locale en-US)
    • Flutter version 2.10.4 at E:\Flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c860cba910 (4 days ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc4)
    • Android SDK at C:\Users\moham\AppData\Local\Android\sdk
    • Platform android-31, build-tools 31.0.0-rc4
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.2)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio22\Community
    • Visual Studio Community 2022 version 17.1.32319.34
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 4.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19043.1586]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 99.0.4844.84
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 98.0.1108.62

[√] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

一切正常。问题出在哪里?

我阅读了之前的所有答案,但对我没有任何帮助。

也许转到 Android Studio,菜单 文件设置外观和行为系统设置SDK 工具.

检查 CMake 字段是否被选中。

另一个:

检查开发者选项是否被选中(在Windows)* 设置更新和安全对于开发人员开发人员模式(如果关闭,请打开)。

解决这个问题有两种可能:

  1. 尝试重新安装 Windows SDK 并再次 运行

  2. 安装 sudo apt-get install build-essential

我解决了这个问题,但我不知道具体的解决方案是什么。

我认为解决方案是从 Visual Studio 中卸载整个“使用 C++ 进行桌面开发”并重新安装。

然后在我的Flutter工程目录下:

flutter cleanflutter create .