Introduction#
Recently, due to various reasons, I have repeatedly configured the C++ environment in VSCode. Therefore, I am writing this note to record how to quickly set up the environment.
I also created two scripts, one for Linux and one for Windows, to easily configure the environment.
The main purpose is to be able to directly copy it later, so there will be many code blocks.
If you think there are any areas where my configuration is not good, please leave a comment.
Prerequisites#
- VSCode and its C/C++ extension have been installed, other extensions are not necessary.
- g++ and gdb have been installed and added to the path. For Windows, it is recommended to use Scoop. I have also written a note.
Scripts#
Emphasis: Change to the directory you want to open with VSCode before running!
- Includes
tasks.json
,launch.json
, and ahelloworld.cpp
. You can also choose to download.gitignore
and.clang-format
. - The compiled executable file is placed in the .build/ folder in the workspace directory.
.gitignore
ignores the.vscode
and.build
folders..clang-format
is my preferred code style, please modify as needed.
{% tabs system %}
Linux Bash (excluding .gitignore and .clang-format):
bash <(wget -qO- https://gist.githubusercontent.com/yy4382/9bc452ef52f89efe9904296947038f25/raw/vsc-cpp-speedrun.sh)
Linux Bash (including .gitignore and .clang-format) (with an additional -a parameter):
bash <(wget -qO- https://gist.githubusercontent.com/yy4382/9bc452ef52f89efe9904296947038f25/raw/vsc-cpp-speedrun.sh) -a
Windows PowerShell:
irm https://gist.githubusercontent.com/yy4382/9bc452ef52f89efe9904296947038f25/raw/vsc-cpp-speedrun.ps1 | iex
For Windows, modify tasks.json as specified in the comments inside.
If you encounter an error about unsigned scripts not being allowed to run on Windows, run the following command first and then try again:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
...
{% endtabs %}
Afterwards, use code .
to open VSCode.
Manual Configuration#
- Complete the prerequisites
The following is a script reference from GitHub Gist. If it does not load, please refresh the page.