Yunfi

Yunfi

tg_channel
github
email

VSCode Setting Up C++ Environment Single Script Quick Pass

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 find any issues with my configuration, 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#

Note: Change to the directory you want to open with VSCode before running the scripts!

  • Includes tasks.json, launch.json, and a helloworld.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 (without .gitignore and .clang-format):

bash <(wget -qO- https://gist.githubusercontent.com/yy4382/9bc452ef52f89efe9904296947038f25/raw/vsc-cpp-speedrun.sh)

Linux Bash (with .gitignore and .clang-format) (add -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 the file.

If you encounter an error about running unsigned scripts on Windows, run the following command before running the script:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

...
{% endtabs %}

Afterwards, use code . to open VSCode.

Manual Configuration#

  • Complete the necessary preparations.

The following is the script reference from GitHub Gist. If it does not load, please refresh the page.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.