VSC configuration C++ compilation environment detailed version


Three steps to complete the VSC configuration C++ environment

1. Tool preparation

First introduce VSC and mingw64

Visual Studio Code (VS Code / VSC for short) is a free and open source modern lightweight code editor that supports syntax highlighting, smart code completion, custom hotkeys, bracket matching, and code for almost all mainstream development languages Snippet, code comparison Diff, GIT and other features, support plug-in extension, and optimized for web development and cloud application development. The software supports Win, Mac and Linux across platforms.
Download link: https://code.visualstudio.com/

mingw64: is the abbreviation of Minimalist GNUfor Windows. It is a collection of freely usable and freely distributed Windows-specific header files and import libraries using the GNU tool set, allowing you to generate native Windows programs on GNU/Linux and Windows platforms without the need for a third-party C Runtime (C Runtime) Library. MinGW is a set of include files and port libraries. Its function is to allow programs in the console mode to use Microsoft's standard C Runtime library (MSVCRT.DLL). This library is valid on all NT OSs. The Windows OS above the Windows 95 release version is valid. When using the basic runtime, you can use GCC to write console mode conforming to the American Standards Organization (ANSI) program, and you can use the C Runtime extension provided by Microsoft to compare with the basic runtime Combining time, you can have full rights to use both CRT (C Runtime) and Windows API functions.
Download link: https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/

2. Configure environment variables

The role of configuring environment variables is that the bin folder of mingw can act on the entire computer, which enables the gcc.exe file in the bin to compile cpp files in other paths across folders.

1. Find the bin path after mingw is installed and copy and paste.
Insert picture description here2. Right-click this computer to enter the properties, and then enter the advanced system settings.
Insert picture description here
3. Enter environment variables.
Insert picture description here
4. Select Path and click Edit.
Insert picture description here
5. Click New and add the copied mingw bin path. Remember that you cannot click the × in the upper right corner of the window, you should confirm all the way to add successfully .

Three. Configure VSC

Note that the path in the configuration file should be \\ instead of \, such as D:\\development\\mingw64\\bin\\gcc.exe. The former \ is to escape the latter \ so that it can express the path.

1. Search and download the corresponding plug-in in the plug-in menu.
Insert picture description here
Insert picture description here
2. Create a new folder in the D disk location to configure C++ and install the C++ code. It is recommended to load files to the D disk. Too many things on the C disk will slow down the system. What I built here is a demonstration folder C++show.
Insert picture description here
3. In the upper left corner of VSC, choose to add the folder to the workspace. Insert picture description here4. Debug hello world. Write the code and press F5 to run. Point enter all the way.
Insert picture description here5. In this way, VSC will automatically find your bin path and generate the configuration folder .vscode. Includes two configuration files.
Insert picture description hereInsert picture description here
6. So normal users can type C++ code on VSC.Insert picture description here

4. Additional problem solving.

#Include error detected. Please update includePath. Squiggles have been disabled for this translation unit (D:\C++ show\hello.cpp).
Insert picture description here

Since I installed VC, all VSC will find the path of my VS, and all need to be replaced with the path of mingw configured by myself.

1. Add configuration under the yellow exclamation point prompt.
Insert picture description here2. Get a configuration file of c_cpp_properties.json.
Insert picture description here3. Update the path path inside. Add a line of your mingw gcc path to the configuration file, and comment out the VS path.

"compilerPath": "D:\\development\\mingw64\\bin\\gcc.exe",

Insert picture description here

4. This is perfect.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_50216270/article/details/112604744