1. 设置
方法一:在UI界面设置,方法是:设置键->Settings
方法二:也可以打开setting.json文件进行设置,方法是:设置键->Command Palette,在选择框的下拉列表中选择“Preferences: Open Settings (JSON)”
2. 控制台
按Ctrl+Shift+P打开VSCode控制台,在控制台中输入命令可以实现很多功能。
3. 打开工程
在VSCode界面点击File->Open Folder,然后选择文件夹
在终端中运行code [project path]
4. 配置文件
用VSCode打开一个工程后,它会在工程中建一个.vscode文件夹,里面有三个文件
tasks.json (compiler build settings)
launch.json (debugger settings)
c_cpp_properties.json (compiler path and IntelliSense settings)
5. 环境配置
c_cpp_properties.json文件主要是设置系统级的大环境,基本上不用改,除非有第三方库
{
"configurations": [
{
"name": "Linux",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
6. 编译
6.1. 自定义编译
主要通过 设置任务(动作)来实现。
tasks.json文件相当于vscode的.sh或.bat文件,用来记录一系列操作的宏。
一系列动作,那就可以用来设置 如何编译文件,如何 运行文件,几乎.sh能干的都可以干。
打开控制台,输入Tasks: Configure Tasks,再选择Create tasks.json file from templates,选择Others模板,就自动生成了一个tasks.json文件,编写参数来调整设置。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build1111", //你的设置文件名,可随便起
"type": "shell", //运行task的平台,一般是shell
"command": "bash ./build.sh", //普通的shell命令,运行你的.sh文件
"group": {