VScode C language environment building tutorial

VScode editor

VScode is a great text editor, but the configuration is a bit cumbersome, especially the C language, which is not out of the box like Visual Studio, but it also provides users with a lot of room for customization. let's start!

Download MinGW-w64 (install gcc via MinGW-w64)

You may also have heard of MinGW. Considering which one is better underground, here is that MinGW's gcc compiler has not been updated for a long time, so I decided to download MinGW-w64, which not only has a comparative gcc compiler, but also Supports 64-bit systems.
First, enter this website https://sourceforge.net/projects/mingw-w64/files/ , scroll down, we can see this.
Insert picture description here
The compressed package installation is chosen here because the .exe installer of MinGW-w64 needs to connect to a foreign country, and the file download speed during the installation process is too slow. Once I waited for a morning and did not finish the installation. . .

FIG accordance with an instruction of downloading (download if the download speed is too slow try Thunder)
after the download is finished a compressed, decompression is completed, as is shown in a folder
(here, selection of i686-win32-dwarf Demo)
Insert picture description here
Next Go to the next step

Install MinGW-w64

We moved the folder to a place, here for convenience I put it directly under the root directory of the C drive, you can also put it in other places, but do not have a Chinese path.
Insert picture description here
The next step is to add environment variables. Right-click "This computer" on the desktop, select "Properties", then click "Advanced system settings", click "Environment variables", and then double-click the "path" environment variables (there are You can
click either of the two paths.) Then click New and enter the path of the mingw32 folder, but note that \bin must be added at the end, like this, you can also click "Browse" on the right to locate the bin of mingw32 Folder to complete the addition.
If it is not Win10, you need to double-click "path" and enter " ;" (English semicolon!!!) at the end of the input box , and then enter

this, Win + r keys to open the command prompt, enter gcc, if the following screen appears , It means that MinGW-w64 is installed successfullyInsert picture description here

Configure VScode

Open VScode, enter C in the extension store input box, and install the C/C++ extension.
Insert picture description here
Then create a new file and pay attention to the path of the folder 全是英文的,不能有中文!, otherwise an error will be reported when debugging later. I created a new folder named project here.
Then open this folder, create a new .c source file and
Insert picture description here
just type a piece of code, then select Terminal on the menu bar, select Configure Default Build Task (configuration task), the default will display gcc.exe, just click it . At this time, you will see a folder named .vscode on the left, which contains the tasks.json configuration file, do not touch it.
Insert picture description here
Select Terminal on the menu bar, click Run Build Task, select gcc.exe, you can see that the file is compiled, and the executable file of HelloWorld.exe appears on the left.

It's not over yet, and debugging.
Select Run on the menu bar, click Add Configuration..., click C++ (GDB/LLDB), and select gcc.exe in the pop-up list. It will start debugging.

The path of the file must be in English!
The path of the file must be in English!
The path of the file must be in English! Otherwise it cannot be debugged successfully

But now there is still a problem, that is, if we let the C language print a section of Chinese and execute the .exe executable file directly in the command prompt after compiling, the output content may be garbled. Why is this?
We see that UTF-8 is displayed in the status bar at the bottom right corner of VScode, which means that the encoding format of our code is UTF-8, but the command prompt is GBK encoding. If the encoding is different, it will be garbled. To solve this, we open VScode settings , Insert picture description here
in the json file which added: "[c]": {"files.encoding": "gbk"},
open the C source file after time, it will automatically open GBK coding, so the compiler will not be garbled after

end

Looking at the details of my tutorial, I’m sure to leave without a thumbs up (please praise)

Guess you like

Origin blog.csdn.net/qq_55058006/article/details/113989597