Windows下VSCode编写C++配置

写在前面

参考:

可能有用:

个人问题

使用mingw-w64-install.exe安装报错

wrong

然后我使用了Cywin(setup-x86_64.exe)

开始配置

  1. 安装Visual Studio Code

  2. 安装插件

C/C++
C/C++

Coder Runner
Coder Runner

  1. 安装GCC(以Cywin为例)
  • 选择下载资源
    Choose A Download Source
  • 选择安装目录
    Select Root InstallD irectory
  • 选择安装包下载目录
    SelectLocalPackageDirectory
  • 选择你的网络连接
    SelectYourInternetConnection
  • 选择下载镜像
    ChooseADownloadSource
  • 选择扩展包
    Select Package

注意:必须勾选GCC

默认等待结束即可。

打开Cygwin64 Terminal检查gcc

gcc

此时已经可以使用GCC编译器

Write With Notepad

为了方便使用,添加到环境变量中。

path

打开powershell检查
gcc yes!

  1. 配置VSCode环境

File -> Preferences -> Settings -> settings.json

settings.json

修改文件中commandcwd,对应本机。

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "g++.exe build active file",
      "command": "F:\\tools\\cygwin\\bin\\g++.exe",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "F:\\tools\\cygwin\\bin"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

重启VSCode

Hello World

写在后面

VSCode本质上应该算是一个编辑器,根据个人需求添加相应插件可以成为顺手的IDE。

在Windows上使用VSCode最麻烦的在于编译器的配置,如果你是Linux,基本上能够做到开箱即用。


comment: