Back to Browse

How to Set Up Visual Studio Code for C & C++ Programming (Step-by-Step Guide)

5.3K views
Jan 5, 2025
14:02

In this video, I walk you through the process of setting up Visual Studio Code (VS Code) to write, compile, and run C and C++ code on Windows. I'll cover everything from installing the Compiler debugger to configuring VS Code, so you can start coding right away. Timestamps for video topics 00:28 Installing gcc, g++ Compiler and gdb debugger 07:16 Check for proper installation of gcc g++ and gdb 08:28 installing vs code 09:53 setting vs code for C C++ Programming Commands used for installing Compiler : pacman -S mingw-w64-ucrt-x86_64-gcc For Installing Debugger : pacman -S mingw-w64-ucrt-x86_64-gdb The first step is to install the C/C++ compilers using MSYS2, a software distribution platform for Windows. Open your browser and go to msys2.org. Download and run the MSYS2 installer. During installation, make sure to note the installation path, which is usually `C:\msys64`. Once MSYS2 is installed, open the MSYS2 terminal. To update the installed packages, run this command: pacman -Syu If there are any updates available, MSYS2 will download and install them. After that, close and reopen the terminal to ensure everything is up to date. After that install the compiler and debugger by using the command provided above. Confirm the installation by typing "Y" when prompted. If any errors occur, try running the commands again. Once the compiler / debugger is installed, we need to update the PATH environment variable so you can use the compilers from any folder on your system. Go to `C:\msys64\usr\bin`, copy the path, and add it to the system’s PATH variable through the “Edit Environment Variables” window in Windows. To confirm the installation, open a new terminal window and type: gcc --version g++ --version gdb --version If the installation was successful, you'll see the version numbers of GCC, G++, and GDB. If you see an error like "command not found," the installation might not have worked properly. Next, I show you how to set up Visual Studio Code. First, go to code.visualstudio.com and download the VS Code installer for Windows. Once the installer is downloaded, run it. During installation, make sure to select the option that adds "Open with Code" to the context menu. This will make it easier to open files directly in VS Code. After installing, launch VS Code. Create a workspace and add a folder to the workspace. create a simple C++ Program. To compile and run this code, you need to install the C/C++ extension for VS Code. Go to the Extensions tab, search for "C++," and install the "C/C++ Extension Pack" by Microsoft. This will allow VS Code to work with the compilers and debugger. Once the extension is installed, go back to your code file. Then, to run the code, click on the play button with the down arrow at the top-right of the screen. Choose the "Run C++ File" option, and make sure to select the `g++` compiler. The code will be compiled, and the output will appear in the terminal at the bottom of the VS Code window. And that’s it! You’ve now set up your system to write, compile, and run C and C++ code in Visual Studio Code. If you found this video helpful, give it a thumbs up. If you have any questions, drop them in the comments below. Don’t forget to subscribe for more tutorials! Our Website https://www.LearningLad.com Social Media Facebook https://www.facebook.com/LearningLad Twitter https://www.twitter.com/LearningLadEdu Instagram https://www.instagram.com/LearningLadOfficial

Download

0 formats

No download links available.

How to Set Up Visual Studio Code for C & C++ Programming (Step-by-Step Guide) | NatokHD