Installation of vscode and configure the c language environment

There is no difficulty in downloading and installing Visual Studio Code, just find the official website https://code.visualstudio.com/ to download and install it.

The more difficult thing is to build a C language development environment. There are a lot of tutorials on the Internet, but it is really difficult for beginners, and there are often many inexplicable errors. No matter what software is installed, the official document given by the official is the most convincing https://code.visualstudio.com/docs/cpp/config-mingw . Many questions can be answered here, but you can also read the official document Relatively difficult, so it is necessary to find high-quality blogs or articles on platforms such as CSDN and Zhihu.

1. The first step, download vscode and MingGW
directly to the official website to download, MingGW download link is MingGW

2. In addition, a very important point when using vscode is that you can install many useful plug-ins according to your needs,
such as the

Chinese (Simplified) Language Pack for Visual Studio Code plug-in, which makes VSCode a Chinese interface.

**C/C++**插件,写C/C++的插件。

**Code Runner**插件,一键运行C/C++/Python/Java等语言程序的插件,这里需要配置一下配置扩展配置,把**run in terminal**勾选上,这样程序就可以在终端运行了。

3. Now you can configure the c language environment
. Create a new folder on the computer desktop or the disk where you downloaded vscode (mine is the E disk), you can name it vscode-c, and
Insert picture description herecreate two more folders in it, respectively .vscode and build. Insert picture description here
After that, you need .vscodeto create three json files in the folder. Insert picture description here
4.1 First, configure the c_cpp_properties.jsonfiles

{
    
    
    "configurations": [
        {
    
    
            "name": "MinGW64",
            "intelliSenseMode": "gcc-x64",
            "compilerPath": "E:\\mingw64\\bin\\gcc.exe",
            "includePath": [
                "${workspaceFolder}",
            "cStandard": "c11"
        }
    ],
    "version": 4
}

The path needs to be changed to the path where you downloaded mingw64.
4.2 Configure the launch.json file

{
    
    
    "version": "0.2.0",
    "configurations": [
        {
    
    
            "name": "C Launch (GDB)", 
            "type": "cppdbg", 
            "request": "launch", 
            "targetArchitecture": "x64", 
            "program": "${fileDirname}/build/${fileBasenameNoExtension}.exe", 
            "args": [], 
            "stopAtEntry": false, 
            "cwd": "${workspaceRoot}", 
            "externalConsole": true,
            "internalConsoleOptions": "neverOpen", 
            "MIMode": "gdb", 
            "miDebuggerPath": "E:\\mingw64\\bin\\gdb.exe", 
            "setupCommands": [
                {
    
    
                    "description": "Enable pretty-printing for GDB",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "compile" 
        }
    ]
}

The file path also needs to be changed

4.3 Configure tasks.json file

{
    
    
    "version": "2.0.0",
    "tasks": [
        {
    
    
            "label": "compile",
            "command": "gcc",
            "args": [
                "${file}",             
                "-o",
                "${fileDirname}/build/${fileBasenameNoExtension}.exe", 
                "-O0",
                "-ggdb3", 
                "-Wall", 
                "-std=c11", 
                "-Wno-format",
                "-finput-charset=UTF-8", 
                "-fexec-charset=GB18030",
                "-D _USE_MATH_DEFINES"
            ],

            "type": "shell",
            
            "group": {
    
    
                "kind": "build",
                "isDefault": true
            },

            "presentation": {
    
    
                "echo": true,
                "reveal": "always", 
                 "focus": false,
                 "panel": "shared" 
            },
        }
    ]
}

  1. Test the c language environment,
    create a new hello.cfile
#include <stdio.h>
int main()
{
    
    
    printf("Hello, world!");

    return 0;
}

Try to run, just click the triangle in the upper right corner, if the output is successful, then the configuration is complete.
Insert picture description here
The configuration of the python language environment is similar to that of the c language, except that the contents of the files that need to be configured are different, and the plug-ins required are also different. We will come back later in time.

After the configuration is complete, there may be various minor problems, such as the problem that the terminal cannot output, remember to see if the previous steps have been completed.

And the terminal output will be garbled in Chinese. At this time, we may need to modify the utf-8 encoding to GBK encoding or GB2312 encoding, so we must often search on Google or various platforms to solve it.

Reference materials:
https://blog.csdn.net/qq_27283619/article/details/103648264

Guess you like

Origin blog.csdn.net/weixin_46530492/article/details/108698192