VS Code to build a C/C++ development environment super detailed tutorial


1. Download and configure MinGW


1. Download and unzip MinGW

Download link : https://sourceforge.net/projects/mingw-w64/files/

Scroll down after opening the link, we download the latest 8.1.0, you can see that there are various versions, here is recommended to downloadx86_64-posix-seh
image-20210126152733663

Version description :

  • X86_X64: 64th

    • win32: Developing Windows programs
    • posix:Develop programs under Linux, Unix, Mac OS and other operating systems

    64-bit has two exception handling models to choose from, which sehare newly invented and sjljancient. seh performance is better, but 32-bit is not supported. sjlj has good stability and supports 32-bit

  • i686: 32nd

    • win32: Developing Windows programs
    • posix:Develop programs under Linux, Unix, Mac OS and other operating systems

    32-bit dwarfand sjljtwo kinds of exception handling model for selection. The performance of dwarf is better than sjlj, but it does not support 64-bit

Click the selected version to download, after downloading, you will get the 7zcompressed file, decompress it to getmingw64
image-20210126153120631


2. Configure environment variables

Click mingw64 to enter and you can see the bindirectory, then add binthe path of the directory to the environment variable
image-20210126153835849

  • Press the Win + Rkey to open the operating window, enter sysdm.cpla carriage return;
  • In the pop-up 系统属性window, select the 高级tab;
  • In the 高级find tab 环境变量button, click the 环境变量button to open the 环境变量window;
  • In the 环境变量window, 系统变量find the area of Pathvariable, double-click Pathappears 编辑环境变量the window;
  • In the 编辑环境变量window, click 新建, enter the path to the bin directory in the new line, and then click OK.

image-20210126153613003
image-20210126153707562


3. Test whether the configuration is successful

Press the Win + Rbutton to open the Run window, enter cmda carriage return, enter the command linegcc -version

C:\Users\zsr204>gcc --version
gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 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.

If the above result appears, it means the installation and configuration are successful



Two, install the C/C++ plug-in

In VS Code in the Ctrl + shift + xopen store, search c/c++, select first be installed
image-20210126154530796



Three, the first program

Create an empty directory, open with VS Code, and then create a .cppfile, write a simple code
image-20210126160309924
after completion, you can see the button is not running; this time we click on the sidebar 运行, click 启动调试
image-20210126160422789
and then select GDB/LLDB
image-20210126160437500
and choose g++.exe
image-20210126160522626
this time being given
image-20210126160618920
attention ! ! This is not a configuration problem, but the .cppfile path cannot contain Chinese. We create a new .cppfile in another English directory and repeat the above code

Follow the above steps again, click to start debugging, select GDB/LLDB, and then select g++.exe. At this time, the following interface will automatically pop up. At this time, we switch to hello.cppand click the run button in the upper left corner to run the
image-20210126161822817
result:
image-20210126162005536
ps: .cppAt the end of the run , a .exefile will also be generated . .cppWhen there are a lot of exefiles, a lot of files will be generated , which seem to interfere with the line of sight, we can set the hidden

Click the lower left corner to open the settings,
image-20210126163417612
swipe down, find Files:Exclude, select the add mode, enter **/*.exe, and click OK.
image-20210126163557033
Then you can't see the exefile, it has been hidden



Fourth, related plug-in recommendation

1. Visual Studio IntelliCode

Visual Studio IntelliCode(IntelliCode) is a set of AI auxiliary functions that can improve the work efficiency of developers through functions such as contextual intelligence, parameter completion, code format and style rule inference.
IntelliCode extends existing developer workflows with machine learning services that can help you understand the code and its context. It is now available for C#, C++ (preview), JavaScript/TypeScript (preview) and XAML code, and will be updated in the future to support more languages.

Official website: https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.VSIntelliCode
image-20210126162650212

2. Code Runner

Run code segments or code files in multiple languages ​​to achieve one-click compilation and operation

Official website: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
image-20210126164053998
After installation, perform the relevant configuration, Ctrl+Shift+popen the command panel and input. 打开设置
image-20210126170308477
Select the first one to open the settings.jsonfile, then add the code shown in the figure below and save
image-20210126170451066
it We can .cppclick the run button in the upper right corner of the file to run with one key,
image-20210126170615095
or right-click run codeto run directly
image-20210126170738498

Guess you like

Origin blog.csdn.net/qq_45173404/article/details/113184612
Recommended