Skip to content

Instantly share code, notes, and snippets.

@erbanku
Last active January 4, 2022 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erbanku/e2c52f5d7c780461b06d9d3d4b7290b7 to your computer and use it in GitHub Desktop.
Save erbanku/e2c52f5d7c780461b06d9d3d4b7290b7 to your computer and use it in GitHub Desktop.

在 VS Code 中准备 C++ 开发环境

Links:

Setting up VS Code for C/C++ development

Using GCC with MinGW

MSYS2

STEP1.在 VS Code 中安装扩展 以下扩展(3、4、5 可选)

Name: C/C++ Id: ms-vscode.cpptools Description: C/C++ IntelliSense, debugging, and code browsing. Version: 1.7.1 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

Name: C/C++ Extension Pack Id: ms-vscode.cpptools-extension-pack Description: Popular extensions for C++ development in Visual Studio Code. Version: 1.1.0 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack

Name: C/C++ Themes Id: ms-vscode.cpptools-themes Description: UI Themes for C/C++ extension. Version: 1.0.0 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-themes

Name: C/C++ Compile Run Id: danielpinto8zz6.c-cpp-compile-run Description: Compile & Run single c/c++ files easly Version: 1.0.15 Publisher: danielpinto8zz6 VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=danielpinto8zz6.c-cpp-compile-run

Name: Better C++ Syntax Id: jeff-hykin.better-cpp-syntax Description: The bleeding edge of the C++ syntax Version: 1.15.10 Publisher: Jeff Hykin VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax

STEP2.

  • 下载 MSYS2
  • 从开始菜单运行 MYSYS2 MYSYS 并按前后顺序运行以下命令:
    • pacman -Syu update the core dependencies and all the packages currently installed on MSYS2
    • pacman -Su
    • pacman -S mingw-w64-x86_64-gcc
    • pacman -S mingw-w64-x86_64-gdb
  • 添加 GCC 到系统环境变量:Windows 设置搜索 “环境” 点开 编辑系统环境变量 在下方系统环境变量里点 Path然后 编辑,添加 GCC 安装目录 C:\msys64\mingw64\bin
  • 检查:重新打开 Terminal 输入 gcc --versiongdb --version 检查配置是否成功,如果显示类似如下内容,那说明配置成功,可以愉快的编写并 debug C++ 代码了😄
gcc.exe (Rev5, Built by MSYS2 project) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
GNU gdb (GDB) 11.1
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Terms

g++ (GCC): GNU c++ compiler invocation command

GDB: Debugger Tool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment