【VSCode】Windows下VSCode编译调试c/c++【更新 2018.03.27】
————————– 2018.03.27 更新————————- // Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file‘s basename
// ${fileDirname}: the current opened file‘s dirname
// ${fileExtname}: the current opened file‘s extension
// ${cwd}: the current working directory of the spawned process
{
"version": "0.2.0","configurations": [
{
"name": "(gdb) Launch","preLaunchTask": "build","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}.exe","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": true,"MIMode": "gdb","miDebuggerPath": "C:/Program Files (x86)/MinGW/bin/gdb.exe",// GDB的路径,注意替换成自己的路径
"setupCommands": [
{
"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true
}
]
}]
}
新的tasks.json // Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file‘s basename
// ${fileDirname}: the current opened file‘s dirname
// ${fileExtname}: the current opened file‘s extension
// ${cwd}: the current working directory of the spawned process
{
"version": "2.0.0","tasks": [
{
"label": "build","type": "shell","group": {
"kind": "build","isDefault": true
},"presentation": {
"echo": true,"reveal": "always","focus": false,"panel": "shared"
},"windows": {
"command": "g++","args": [
"-ggdb",""${file}"","--std=c++11","-o",""${fileDirname}${fileBasenameNoExtension}.exe""
]
}
}
]
}
懒得自己配置或自己配置出现不明问题的朋友可以点这里: ————————– 2017.06.10 更新 (已过时)————————- 便携版已更新,点此获取便携版 // Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file‘s basename
// ${fileDirname}: the current opened file‘s dirname
// ${fileExtname}: the current opened file‘s extension
// ${cwd}: the current working directory of the spawned process
{
"version": "0.2.0","configurations": [{
"name": "C++ Launch (GDB)",// 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg",// 配置类型,这里只能为cppdbg
"request": "launch",// 请求配置类型,可以为launch(启动)或attach(附加)
"targetArchitecture": "x86",// 生成目标架构,一般为x86或x64,可以为x86,arm,arm64,mips,x64,amd64,x86_64
"program": "${file}.exe",// 将要进行调试的程序的路径
"miDebuggerPath": "C:MinGWbingdb.exe",// miDebugger的路径,注意这里要与MinGw的路径对应
"args": [],// 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false,// 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${fileDirname}",// 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"externalConsole": true,// 调试时是否显示控制台窗口,一般设置为true显示控制台
"preLaunchTask": "g++" // 调试会话开始前执行的任务,一般为编译程序,c++为g++,c为gcc
}]
}
更新的tasks.json {
"version": "0.1.0","command": "g++","args": ["-g","${file}","${file}.exe"],// 编译命令参数
"problemMatcher": {
"owner": "cpp","fileLocation": ["relative","${workspaceRoot}"],"pattern": {
"regexp": "^(.*):(d+):(d+):s+(warning|error):s+(.*)$","file": 1,"line": 2,"column": 3,"severity": 4,"message": 5
}
}
}
懒得自己配置或自己配置出现不明问题的朋友可以点这里: ————————– 以下是原文 ————————- 这篇文章为blackkitty记录在windows下使用vscode编译调试c/c++的详细过程 首先看效果 条件断点的使用: 下面是配置过程: 总体流程:
下载安装vscode 点击下载自己喜欢的相应版本,绿色版解压即可食用 安装cpptools插件
vscode在短暂的联网查找后会列出插件列表,如图: 点击箭头所指处的按钮安装插件,安装过程可能会有些慢耐心等待 安装完成后vscode会提示你重启vscode,此时重启即可 安装编译、调试环境 目前windows下调试仅支持 Cygwin 和 MinGW。 选择一个安装目录,默认为C:MinGW这里选择的是A:MinGW 打开MinGW安装管理器进行进一步配置 注意这里gdb必选,否则无法调试 选中几个需要的项右键Make for Installation进行标记,其中gcc和g++为c和c++编译器 选择完全部想要安装的项后点击左上角Installation菜单下的Apply Changes应用修改,过程需联网,中间出现error可先继续,若最后失败则需FQ更新,建议FQ 然后配置系统环境变量path,这一步为必须 修改vscode调试配置文件 打开文件夹后,新建test.cpp进行输入代码测试: 如图示进入调试界面选择C++: 然后会在工作目录下的生成一个launch.json的启动配置文件: 使用下面代码替换该文件: {
"version": "0.2.0","configurations": [
{
"name": "C++ Launch (GDB)",// 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg",// 配置类型,这里只能为cppdbg
"request": "launch",// 请求配置类型,可以为launch(启动)或attach(附加)
"launchOptionType": "Local",// 调试器启动类型,这里只能为Local
"targetArchitecture": "x86",x86_64
"program": "${file}.exe",// 将要进行调试的程序的路径
"miDebuggerPath":"a:MinGWbingdb.exe",// miDebugger的路径,注意这里要与MinGw的路径对应
"args": ["blackkitty","1221","# #"],// 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false,// 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceRoot}",// 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"externalConsole": true,// 调试时是否显示控制台窗口,一般设置为true显示控制台
"preLaunchTask": "g++" // 调试会话开始前执行的任务,一般为编译程序,c++为g++,c为gcc
}
]
}
注意miDebuggerPath要与MinGw的路径对应 在这里随便选一个: 然后用下面代码替换: {
"version": "0.1.0","message": 5
}
}
}
保存一下,然后切换至test.cpp,再次按F5启动调试~ 完了! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows-phone-7 – 参数不正确 在MS.Internal.XcpImports.
- windows-7 – 如何为Windows Vista / 7开发Metro应用程序UI
- Windows – 如何在Visual Basic 6.0中创建清单文件?
- xaml – x中ElementName的替代:与DataTemplates绑定
- 适用于Skype的Android Api?
- Windows更新 – Windows Server Update Services(WSUS)3.0
- winapi – Win32控制台问题
- powershell – “get-wmiobject win32_process -computerna
- .net – PowerShell中的echo和Write-Host有什么区别?
- Windows机器的正常运行时间
- windows-server-2008 – 为什么Windows 2K3 / 2K
- ffmpeg命令行,用于使用Windows 7从decklink卡捕获
- windows平台安装配置Gitblit
- 身份验证错误 要求的函数不受支持 Windows远程桌
- audio – 在Windows Phone 8中以编程方式下载媒体
- 如何在Windows 7中使用cmd使用cURL发布XML数据?
- Windows pip安装
- windows-server-2008 – FTP服务器的建议,允许限
- 批处理文件 – Dos批处理:写入没有行结尾的文件
- 如何在WiX中检查.NET framework 4.5 prerequesti