【发布时间】:2021-12-22 20:43:41
【问题描述】:
我认为我输入了所有正确的设置,但它给了我一个预启动任务错误,因为程序包含多个文件,所以我尝试更正 tasks.json 设置并将 args 设置为“*.cpp”,但我仍然有同样的问题。
请注意,所有文件都在同一个文件夹中,并且在编译过程中我没有错误。
预启动任务错误:
在 tasks.json 的 args 中设置“*.cpp”后,我仍然得到之前的错误 + 这个:
launch.json 设置:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false, //set to true to see output in cmd instead
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
},
{
"name": "g++ build & run active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false, //set to true to see output in cmd instead
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build & run active file"
}
]
}
tasks.json 设置:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
}
},
{
"type": "shell",
"label": "g++ build & run active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
}
}
],
}
【问题讨论】:
-
请edit提出问题并添加按下
Show Errors按钮时出现的文字。 -
@KenY-N 完成了,你有解决方案吗?
-
@VladfromMoscow 请问您知道解决方案吗?
-
您的源文件必须在子目录中。
-
这就是问题所在,您应该将测试目录中的 cpp 文件移动到其父文件夹,即您的项目文件夹,该文件夹应该是工作目录。或者你必须在执行 g++ cmd 之前 cd 到测试目录。
标签: c++ visual-studio-code vscode-debugger