【发布时间】:2021-08-16 16:40:16
【问题描述】:
我搜索了一个星期的解决方案,但不在这里发布就无法解决这个问题。
我在 Vs 代码中用 C 编写代码,到目前为止(在笔记本电脑上)我没有遇到任何问题。前几天调试突然停止工作;这是怎么回事: 简单的代码如:
#include <stdio.h>
int main(){
int x;
x=1;
x*=10;
printf("\ntest %d",x);
}
我按下绿色箭头播放按钮来运行它。我编译和构建很好(根据task.json),但是没有命中断点,并且“printf”在集成终端中也没有得到任何结果。 “调试控制台”也没有显示任何内容
这是我的 task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe compile active file",
"command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"isDefault": true,
"kind": "build",
},
"detail": "compiler: C:\\msys64\\mingw64\\bin\\gcc.exe"
}
]
}
还有我的launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Compile and run debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Abilita la riformattazione per gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe compile active file"
}
]
}
我还尝试并重新安装了所有 Vs 代码、C/C++ Intellisense、扩展运行代码,取消了 mingw 并按照“https://code.visualstudio.com/docs/cpp/config”中的步骤重新安装了它-mingw”。 但是“缺少调试”的行为仍然存在。
另一方面,如果我在集成终端 (powewrshell) 中手动运行 test.exe,只需键入“.\test.exe”,它就可以正常工作。
有什么想法吗?谢谢
【问题讨论】:
-
我看到很多这样的问题。也许尝试this extension 而不是默认的C++?它适用于我在 Linux 上。
-
找到错误报告。那里有一些建议:github.com/microsoft/vscode-cpptools/issues/7971
-
我点击了 HilyBlackCat 报告的错误报告的链接并解决了这个问题:Microsoft C/C++ 智能感知扩展的 1.6 版存在错误,所以我只是重新安装了 1.51 以前的版本。您建议的替代方案也适用于我的其他 Linux 笔记本电脑,非常感谢!
标签: c visual-studio-code mingw-w64 vscode-debugger