VSCode WSL use of GCC c ++ compiler and GDB debugger

WSL use: Ubuntu18.04
use WSL rather than the benefits of installing Mingw-64 on Windows, you can get a similar experience in the development of linux deployment on Windows.

The process is divided into the following steps:

  1. Installation VSCode
  2. Remote-WSL VSCode mounting extensions and C / C ++ extensions
  3. Install and configure WSL
  4. Configuration VSCode

Installation VSCode

  1. In the official website to download VSCode, as no special requirements, the default installation.

Remote-WSL mounting extension

  1. As shown, the first plug is a

  2. Similarly, the first FIG.

Installation WSL

  1. Want to install WSL,
    one needs to open virtualization in the BIOS,
    and second, Control Panel -> Programs and Features -> Enable or disable Windows features, open the Hyper-V and Windows subsystem for Linux

  2. After the restart, directly to the Microsoft Store you can download and install in Ubuntu

  3. Once installed, open the Ubuntu, WSL set of account and password
    • USTC source

      deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
      deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
      deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
      deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
      deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
      deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
      deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    • Replacement source software

      # 打开source.list,将文件内容替换为上述清华源,具体vim如何操作可以百度
      sudo vim /etc/apt/source.list
    • Install gnu compiler and gdb debugger

      sudo apt-get update
      sudo apt-get install build-essential gdb
    • G ++ and gdb to check whether the installed

      whereis g++
      whereis gdb
  4. Configuration VSCode
    • In Ubuntu, create projects folder, and create subfolders in projects helloworld folder

      mkdir projects
      cd projects
      mkdir helloworld
    • Hello into the folder

      # 进入hello文件夹
      cd $HOME/projects/helloworld
      code .

      At this time, VSCode will download and install a small server, and then connect with them in Windows VSCode in the WSL.

    • Finally, open the extended search market C / C ++ extensions, choose to install in the WSL, and then reload.

In the test VSCode

  1. Create a file in VSCode in helloworld.cpp
  • #include <iostream>
    #include <vector>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
    
        for (const string& word : msg)
        {
            cout << word << " ";
        }
        cout << endl;
    }
  1. Create a file to tell VS Code tasks.json how to build (compiled) program
    • From the main menu, select Terminal> Configure Default Build Task.

    • 按Ctrl + Shift + B编译helloworld.cpp文件,生成可执行文件helloworld,成功后如下图所示

    • 点击图中的加号,在WSL中以helloworld文件夹为工作目录运行一个bash终端,此时输入 ls,可以看到一个没有扩展名的可执行文件helloworld,之后在bash中输入 **./helloworld运行该文件,输出得到:

Guess you like

Origin www.cnblogs.com/tangzz/p/11955012.html