VScode配置配置C++环境,环境,preLaunchTask”g++”已终止,退出代码为已终止,退出代码为1解决办法解决办法
记录一下用VScode配置C++环境时遇到的坑。一开始是按照https://blog.csdn.net/bat67/article/details/76095813来配置的,结果后来出现退出代码为1的错误。后来是根据官方文档解
决的。官方文档链接:https://code.visualstudio.com/docs/cpp/config-msvc
首先下载mingw-w64版本的,下载地址:https://sourceforge.net/projects/mingw-w64/
然后将bin所在文件夹加入到系统环境变量中。比如我的就是
接下来就是按照官方文档中的步骤来配置三个json文件。至于三个json文件是怎么生成的,我就不写了,可以参考上面那篇博客或者直接官方文档(* ̄︶ ̄)。
我的三个文件最后的代码分别是:
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
] }
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb",
"miDebuggerPath": "D:\mingw-w64\mingw32\bin\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true