C++ on WSL
C++ on WSL
These documentation is completely followed by the official VsCode document.
Using VsCode to edit source code, compiling the source code on Linux using the g++ compiler and debugging on Linux using GDB. They are not installed by default on Ubuntu.
update sys dependencies:
sudo apt-get update
or download the latest versions of the system packages as well by:
sudo apt-get update && sudo apt-get dist-upgrade
install GNU compiler tools and the GDB debugger:
sudo apt-get install build-essential gdb
verify g++ and gdb:
whereis g++ whereis gdb
After setting up the environment, create a
.cpp file and vscode will pop up a hint window to ask you to install C/C++ extensions. Let's omit this step and head forward to the next step.
Terminal > Configure Default Build Task and in the dropdown select
C/C++: g++ build active file. A
tasks.json file should be created in the
.vscode folder. Learn more
tasks.json variables in the variables reference.
Tasks: Run Build Task and will see an executable file after the build is done.
F5 and choose
C++ (GDB/LLDB), then choose
g++ build and debug active file from the dropdown. This will create a
launch.json file in the
.vscode folder. More details please visit debug-helloworldcpp.
In order to get more control over the C/C++ extension, we can create a
c_cpp_properties.json file in
.vscode folder via
C/C++: Edit Configuration (UI) command.