我正在嘗試設定 VSCODE 以使用 Cygwin64 在 Windows 上除錯C 程式。
我使用了@stephw 建議的配置(
我改變了我的launch.json一點點。請注意,“preLaunchTask”鍵的值與“label”鍵的值不同tasks.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 build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "%PATH%;C:\\cygwin64\\bin"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\cygwin64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": { "engineLogging": true }, //optional
"preLaunchTask": "gcc.exe build active file"
}
]
}
我的tasks.json就是這個(最后注意我的名字,在“detail”鍵中):
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C : gcc.exe build active file",
"command": "C:\\cygwin64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Leonardo."
}
]
}
我注意到一些奇怪的事情:當我按 F5 時,它不起作用,因為找不到創建的任務。

當我將launch.json檔案(preLaunchTask 鍵)編輯為檔案中完全相同的值時tasks.json,“未找到”錯誤消失,但除錯程序不會啟動。
"preLaunchTask": "C/C : gcc.exe build active file"
如果我按下運行和除錯播放按鈕,除錯程序也不起作用。

當我使用命令面板(按 CTRL SHIFT P)并單擊時C/C : Build and Debug Active File,

然后選擇我創建的任務(第二個似乎是自動的),

編譯程式并啟動除錯程序。
這是我非常簡單的測驗腳本:
#include <stdio.h>
#include <stdlib.h>
int main() {
/* declare and initialize string */
char myString[] = "This is an example of string declaration!";
/* print string */
printf("%s", myString);
int numberA = 5;
int numberB = 10;
int sum = numberA numberB;
/* Printing a number */
printf("A soma de numberA numberB é: %d", sum);
return 0;
}
我希望這個問題和答案可以在將來對某人有所幫助。和平。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/343345.html
