VSCode C ++ environment configuration tutorial (ultra-detailed)

Introduction: VSCode editor as a lightweight, compact and lightweight, full-featured, good-looking page, but also much faster than the speed of the VS. Amway crazy.

Preparation Resources: Because the software is downloaded in two foreign websites, so sometimes there will be very slow to download, or when the page is not open. Here I put the link Baidu network disk write here the network disk link , extraction code 1pac

1. Download codeblocks compiler

◆ must first install codeblocks compiler in your computer, there's no compiler vscode is not complete compilation. Click here to download ☞ download site .
Pictures download page
◆-17.12mingw-the setup.exe Download CodeBlocks
Here Insert Picture Description
◆ Download
Here Insert Picture Description
Here Insert Picture Description
◆ then have been next on the line, do not want anything to change.

2. Configure codeblocks environment variables

Codeblocks path ◆ The installation file in the bin folder added to the system path variables,
I was installed in the D drive D: \ Program Files (x86) \ CodeBlocks \ MinGW \ bin ,
usually installed in the default path is C disk C : \ Program Files (x86) \ CodeBlocks \ MinGW \ bin

◆ First, right-click this computer, open the properties
Here Insert Picture Description
Here Insert Picture Description
◆ then it has been determined point on the line.

3. Download and install VSCode

◆ Click here to download ☞ VSCode download site
◆ pulled the bottom of the page, download the 64-bit, if your computer is to download the 32-bit 32bit
Here Insert Picture Description
◆ then remember this during the installation of a few, so that you can directly choose the right mouse button on click to open the folder.Here Insert Picture Description

◆ first language is set to Chinese

Here Insert Picture Description

◆ then the lower right corner under a window will pop up, click Restart Now.
Here Insert Picture Description

◆ install c ++ plug-ins
Here Insert Picture Description

◆ then create a test folder on the desktop, with VSCode open, create a new file hello, the suffix is ​​cpp.

#include<iostream>

using namespace std;

int main()
{
    cout<<"Hello World";
    system("pause");
}

◆ Press Fn and F5 to debug, are selected first.

Here Insert Picture Description
Here Insert Picture Description

◆ then will generate a launch.json file, and then replace the following code inside it. However, to note here is the path according to their actual installation to change, if you are installed in C drive, then changed to C to D better.
Here Insert Picture Description

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg", // 配置类型,这里只能为cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,我一般设置为true
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录
            "environment": [], // (环境变量?)
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
            "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?
            "MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但目前lldb在windows下没有预编译好的版本。
            "miDebuggerPath": "D:\\Program Files (x86)\\CodeBlocks\\MinGW\\bin\\gdb32.exe", // 调试器路径,Windows下后缀不能省略,Linux下则去掉
            "setupCommands": [ // 用处未知,模板如此
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "Compile" // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应
        }
    ]
 }

◆ hello and then return to this page and continue to debug the program, will appear as shown below, click configuration tasks. Choose the first one.
Here Insert Picture Description
Here Insert Picture Description

◆ then there will be a task.json file, put the following into the replacement OK.

{
"version": "2.0.0",
"tasks": [
    {
        "label": "Compile",
        "command": "g++",
        "args": [
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}.exe",
            "-g",
            "-Wall",
            "-static-libgcc",
            "-std=c++17"
        ],
        "type": "shell",
        "group": {
            "kind": "test",
            "isDefault": true
        },
        "presentation": {
            "echo": true,
            "reveal": "always",
            "focus": false,
            "panel": "shared"
        }
    }
]
}

◆ OK, done.

Here Insert Picture Description

Released two original articles · won praise 0 · Views 22

Guess you like

Origin blog.csdn.net/weixin_44881648/article/details/104304228