• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VSCode配置c++环境简单教程

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.下载MinGW

安装有关gdb,gcc,g++的所有包

2.文件夹

打开一个文件夹
在里面随便写一个cpp
不管是VS还是VSCode,它的基本操作单位都是文件夹(项目)

3.配置launch.json


这三个文件都在文件夹的.vscode中如果MinGW被加载到path中就不需要第5步了

{
	"version": "0.2.0",
	"configurations": [{
		"name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
		"type": "cppdbg", // 配置类型,这里只能为cppdbg
		"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
		"launchOptionType": "Local", // 调试器启动类型,这里只能为Local
		"targetArchitecture": "x86", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
		"program": "${file}.exe", // 将要进行调试的程序的路径
		"miDebuggerPath":"C:\\MinGW\\bin\\gdb32.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
		//"args": [""], // 程序调试时传递给程序的命令行参数,一般设为空即可
		"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
		"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
		"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
		"preLaunchTask": "C:\\MinGW\\bin\\g++.exe"   // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
	}]
}

4.配置tacks.json

忘了这个玩意是从哪里冒出来的啦
反正随便一搞就冒出来啦

    {
    	"version": "0.1.0",
    	"command": "C:\\MinGW\\bin\\g++.exe",
    	"args": ["-g","${file}","-o","${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
    		}
    	}
    }

5.配置c_cpp_properties.json文件

{
"configurations": [
{
"name": "Mac",
"includePath": [
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
]
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
},
{
"name": "Win32",
"includePath": [
"C:\\MinGW\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++",
"C:\\MinGW\\include\\c++\\3.4.5",
"C:\\MinGW\\include\\c++\\3.4.5\\mingw32",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include\\c++\\tr1",
"${workspaceRoot}"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 3
}

6.F5运行调试

完事
不过在调试控制台中输入gdb的命令需要加"-exec"
例如"-exec list"


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
[转]C#实现在SqlServer中存储和读取Word文件(NotCorrectModified)发布时间:2022-07-14
下一篇:
C#删除文件夹以及删除文件发布时间:2022-07-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap