[C语言基础] 一、Visual Studio Code C语言开发环境搭建

Visual Studio Code C语言开发环境搭建

一、Visual Studio Code安装与主题配置

1、Visual Studio Code安装

Visual Studio Code安装程序下载地址: https://code.visualstudio.com/

2、配置中文主题

1)打开扩展(Ctrl+Shift+X)输入 Language 搜索 Chinese (Simplified) Language Pack for Visual Studio Code点击安装
2)打开命令面板(Ctrl+Shift+P ),输入Configure Display Language 选择zh-cn,软件重新启动切换到中文界面

3、配置字体颜色主题
  1. 打开扩展(Ctrl+Shift+X)输入 theme搜索 Dracula Official 点击安装
4、配置文件图标主题
  1. 打开扩展(Ctrl+Shift+X) 输入 theme 搜索 Material Theme Icons点击安装

二、安装C / C ++扩展。

打开扩展(Ctrl+Shift+X) 输入C / C ++搜索C / C ++插件,作者为Microsoft

三、编译与调试配置

1、创建工作空间

启动Visual Studio Code,在界面下部终端处输入命令创建工作空间项目目录

mkdir Clang_Workspace
cd Clang_Workspace
mkdir helloworld
cd helloworld
code .

code .命令会打开一个新的Visual Studio Code工作窗体并导航到当前项目路径。在配置的过程中,Visual Studio Code会自动创建一个.vscode文件夹,此文件夹中保存着一些自定义的项目配置文件。C语言开发主要用以下三个配置文件:
c_cpp_properties.json (编译器路径和IntelliSense设置)
tasks.json (编译设置)
launch.json (调试器设置)

2、创建配置文件

配置文件既可手动添加文件,也可以从命令面板中创建。

2.1 c_cpp_properties.json文件

打开命令面板(Ctrl+Shift+P)输入edit configurations选择c/C++:Edit Configurations (JSON)自动创建文件,可以自定义修改参数并保存即可。

{
  "configurations": [
    {
      "name": "Win32",
      "includePath": ["${workspaceFolder}/**"],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "windowsSdkVersion": "10.0.18362.0",
      "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe",
      "cStandard": "c11",
      "cppStandard": "c++17",
      "intelliSenseMode": "msvc-x64"
    }
  ],
  "version": 4
}

includePath :包含目录路径或源文件目录路径
compilerPath:编译器的路径,开发工具使用它来推断C 标准库头文件的路径

2.2 tasks.json 文件

tasks.json文件主要告诉VS Code如何构建(编译)程序。
打开命令面板(Ctrl+Shift+P)输入Configure Task选择>Tasks:Configure Task弹出使用模板创建tasks.json文件

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "Microsoft_Task",
      "command": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe",
      "args": [
        "/Zi",
        "/EHsc",
        "/Fe:",
        "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "${file}"
      ],
      "problemMatcher": ["$msCompile"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

label:Tasks名称,在launch.json使用此名称与tasks.json作关联
command:定要运行的编译工具
args:该args数组参数即是传送到command中指定编译工具的命令行参数。其参数说明请另行查找相关说明

2.3 launch.json 文件

tasks.json文件主要配置程序的调试信息
打开命令面板(Ctrl+Shift+P)输入Open launch.json选择Debug:Open launch.json找开文件

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "cl.exe build and debug active file",
      "type": "cppvsdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false, //主函数入口是否添加调试断点
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "preLaunchTask": "Microsoft_Task"
    }
  ]
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值