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:
- Installation VSCode
- Remote-WSL VSCode mounting extensions and C / C ++ extensions
- Install and configure WSL
- Configuration VSCode
Installation VSCode
- In the official website to download VSCode, as no special requirements, the default installation.
Remote-WSL mounting extension
As shown, the first plug is a
Similarly, the first FIG.
Installation WSL
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 LinuxAfter the restart, directly to the Microsoft Store you can download and install in Ubuntu
- 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
- 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
- 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; }
- 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运行该文件,输出得到: