栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Vscode 配置 c++ 编译环境踩坑记录

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Vscode 配置 c++ 编译环境踩坑记录

文章目录
  • task.json
  • launch.json
  • setting.json
  • F5 运行错误
    • 原因

task.json
{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "task g++",
			"command": "C:\Environment\mingw64\bin\g++.exe",	//修改为自己路径
			"args": [
				"-g",	//g++ -g
				"${file}",	//g++ -g main.cpp
				"-o",	//g++ -g main.cpp -o
				"${fileDirname}\${fileBasenameNoExtension}.exe"	//g++ -g main.cpp -o main.exe
			],
			"options": {
				"cwd": "${workspaceFolder}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"presentation": {
				"panel": "shared"
			}
			
	
		}
	]
}
launch.json
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,   //改为true
            "preLaunchTask": "task g++",    //新增项
            "MIMode": "gdb",
            "miDebuggerPath": "C:\Environment\mingw64\bin\gdb.exe", //MinGW位置
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
setting.json
{
    "tabnine.experimentalAutoImports": true,
    "editor.fontSize": 17,
    "editor.renderWhitespace": "all",
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "terminal.integrated.profiles.windows": {
        "Git Bash": {
            "source": "Git Bash"
        },

        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\Sysnative\cmd.exe",
                "${env:windir}\System32\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "cmder":{ //使用 cmder 作终端
            "path": "C:\KcSoftware\cmder\vendor\git-for-windows\bin\bash.exe",
            "args":[]
        },
    },
    
}

F5 运行错误
> Executing task: C:Environmentmingw64bing++.exe -g d:MyCodeSpaceVsCodevscode-testhello.cpp -o d:MyCodeSpaceVsCodevscode-testhello.exe <

/usr/bin/bash: C:Environmentmingw64bing++.exe: command not found
终端进程“C:Program FilesGitbinbash.exe '--login', '-c', 'C:Environmentmingw64bing++.exe -g d:MyCodeSpaceVsCodevscode-testhello.cpp -o d:MyCodeSpaceVsCodevscode-testhello.exe'”已终止,退出代码: 127。

原因

设置了默认 shell 为 git bash,注掉这一句调试正常,

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/928402.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号