I want to debug the flutter demo application on windows x64 device.but it always fails with 1 error and 1 warning this is my Debug console :
Launching lib\main.dart on Windows in debug mode...
lib\main.dart:1
F:\flut\flutter_application_5\windows\runner\utils.cpp(52,43): error C2220: warning treated as error - no 'object' file generated [F:\flut\flutter_application_5\build\windows\runner\flutter_application_5.vcxproj]
F:\flut\flutter_application_5\windows\runner\utils.cpp(52,43): warning C4018: '>': signed/unsigned mismatch [F:\flut\flutter_application_5\build\windows\runner\flutter_application_5.vcxproj]
Exception: Build process failed.
and here is my flutter doctor log :
[flutter] flutter doctor -v
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.19044.1826], locale en-US)
• Flutter version 3.0.5 at C:\src\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (6 weeks ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\MEMPHIS\AppData\Local\Android\sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12 7-b1504.28-7817840)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Enterprise 2019 16.1.0)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
• Visual Studio Enterprise 2019 version 16.1.28917.181
• Windows 10 SDK version 10.0.17763.0
[√] Android Studio (version 2021.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.12 7-b1504.28-7817840)
[√] VS Code (version 1.70.2)
• VS Code at C:\Users\MEMPHIS\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.46.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1826]
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.102
• Edge (web) • edge • web-javascript • Microsoft Edge 104.0.1293.63
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
exit code 0
I can debug the demo app on edge, chrome, android without any problem so What wrong?
CodePudding user response:
The (Microsoft) C compiler is raising a warning inside the utils.cpp
file:
windows\runner\utils.cpp(52,43): warning C4018: '>': signed/unsigned mismatch
It's configured to treat warnings as errors, so the compile fails with:
windows\runner\utils.cpp(52,43): error C2220: warning treated as error - no 'object' file generated
I don't believe that /WX
(warnings as errors) can be configured other than by the build script (which turns it ON).
I suspect one of two things:
- The Enterprise edition of the compiler (which you have) is slightly more picky than the Community edition (which I have). You could edit the project file to turn off warnings-as-errors, or add an exception for this warning (more below).
- Your compiler needs upgrading. I've got 16.11.something; you've got 16.1.something. Run the Visual Studio Installer again to upgrade it. (For example: I just ran it, and it's suggesting I upgrade from 16.11.10 to 16.11.18...).
Editing the project file
The winapp.vcxproj
project file is (apparently) generated by CMake. Edit windows\CMakeLists.txt
and change the following line:
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
Make it look like this:
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100" /wd4018)
I don't know where the quotes come from; you might need them. Alternatively, remove the /WX
bit.