目录
1.下载安装包
2 插件安装
2.1 C/C++ 必备安装的
2.2 其它辅助的
3. 设置
3.1 函数大纲
3.2 设置喜欢的主题颜色
4.搭建C++编译调试环境
1.下载安装包
建议下载exe安装,安装后可以在右键菜单栏里显示,下载地址:
xvscode官网
https://code.visualstudio.com/
直接可以鼠标右键,将工程代码打开
2 插件安装
2.1 C/C++ 必备安装的
<1>开发C/C++必备的安装
<2>CSS Peek:看函数和变量定义,并且能查找相关的引用
<3>Prettier -Code formatter:代码格式化
<4>Bracket Pair Colorizer :这款插件可以给()、[]、{}这些常用括号显示不同颜色
2.2 其它辅助的
<1>Code Spell Checker
开发人员遇到的大量异常通常可以通过更正变量、函数和程序包名称中的拼写错误来解决
比如输入starrt,就会出现错误的提示,写成start后就正常了
<2>Remote-SSH: 远程连接服务器
<3>Trailing Spaces
空格标红,代码格式化后,这块红色会去掉
<4>Markdown All in One:支持markdown文档
3. 设置
3.1 函数大纲
怎么可以看代码的函数列表:
Ctrl+Shift+P(命令窗口) -> View: Quick Open View -> outline
怎么可以看代码的函数列表:
Ctrl+Shift+P(命令窗口) -> View: Quick Open View -> outline
OUTLINE:
3.2 设置喜欢的主题颜色
先下载主题"Slack Theme"
然后在setting.json里,写入如下的内容
{
"workbench.colorCustomizations": {
"list.inactiveSelectionBackground": "#C5DEF0",
"sideBar.background": "#C5D2DE",
"sideBar.foreground": "#0a0a0a",
"editor.background": "#D2DED1",
"editor.foreground": "#0c0101",
"sideBarSectionHeader.background": "#CAC9C9",
"sideBarSectionHeader.foreground": "#000000",
"activityBar.border": "#FFFFFF",
"statusBar.background": "#525357",
"scrollbarSlider.activeBackground": "#77D4CB",
"scrollbarSlider.hoverBackground": "#8CE6DA",
"badge.background": "#81CA91"
},
"editor.fontSize": 16,
"editor.tokenColorCustomizations": {
"numbers": "#ff0000",
"comments": "#ada6ad",
"functions": "#008000",
//"variables": "#061acc",
//"types": "#0D7C28",
//"keywords": "#008030",
//"strings": "#ffffbb",
},
"workbench.colorTheme": "Slack Theme Hoth",
"files.autoGuessEncoding": true,
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"security.workspace.trust.untrustedFiles": "open"
}
3.3 文件编码全局设置
设置文件编码全局,可以解决搜索不到中文的问题
如果工程的文件都是gbk的编码格式,而vscode的默认编码是UTF8,会出现搜索不到中文
设置: File >> Preferences >> Setting >>Text Editor >>Files>>Encoding
嵌入式调试
VSCode 搭建 Arm 远程调试环境的步骤详解 - 易采站长站 (easck.com)
4.搭建C++编译调试环境
<1>.搭建mingw环境
参考网址: ffmpeg的编译里的msys2的安装,安装并更新国内源后,执行下面的命令:
pacman -S base-devel pacman -S mingw-w64-x86_64-gcc pacman -S mingw-w64-x86_64-gdb
添加MinGW-w64的系统 环境变量
电脑属性->高级系统设置->环境变量->Path,添加:
D:msys64mingw64bin
<2>新建文件夹 .vscode,里面再建下面三个文件,
参考这篇文章:
c_cpp_properties.json
launch.json
tasks.json
//c_cpp_properties.json文件的内容
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
//此处是编译器路径,以后可直接在此修改
"compilerPath": "D:/msys64/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
//launch.json文件的内容
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
"type": "cppdbg",//配置类型,只能为cppdbg
"request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}\${filebasenameNoExtension}.exe",//调试程序的路径名称
"args": [],//调试传递参数
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
"MIMode": "gdb",
"miDebuggerPath": "D:/msys64/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
//tasks.json
{
// See https://go.microsoft.com/fwlink/?linkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file", //这里注意一下,见下文
"command": "D:\msys64\mingw64\bin\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\${filebasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\msys64\mingw64\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
<3>安装Code runner :运行调试代码的插件
<4>按F5 运行调试代码,在菜单的Run里
//main.cpp:在.vscode文件夹相同路径下 #includeusing namespace std; int main() { cout << "hello vscode" << endl; return 0; }
引用这篇文章: Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++
"一劳永逸:因为VS需要为每一个文件夹做单独配置,所以建议把.vscode文件夹放到你常用的文件夹的顶层,这样就不用重复配置了。
不用每个新cpp文件就要一套配置。这些配置在你配置好的文件夹内的所有子文件夹和文件都能使用。"



