How to Compile C++ in VSCode on Windows 11
I have started to learn C++ that I am familiar from C. From the beginning of this journey, I decided to write blog posts and codes about C++ learning. The first challenge is deciding which compiling method I should use. Actually, I think, it’s not a big deal, I just needed to pick one of them. And for those who can’t decide, I will show the method I learned and used from the VSCode website.
1. Install C/C++ extension for VSCode
2. Download and Install MSYS2
You can download MSYS2 from here.
And next->next->next :D
3. Open MSYS2 MINGW64 Terminal
4. Install g++
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
5. Copy the MINGW64/bin Path
If you install with default options, MINGW64 will be installed in the path below. Copy the path.
C:\msys64\mingw64\bin
6. Add the Path to Environmental Variables
Go to Windows Settings. Seach for "edit environmental variables". Then edit Path in User Variables:
7. Check MINGW64 Installation
Open new Command Prompt or Terminal and write commands below:
gcc --version
g++ --version
gdb --version
8. VSCode Activation
Created new folder and opened on VSCode.
If it asks you “Do you trust the authors of the files in folder?”, Check the “Trust the authors of all files in th parent folder” option.
Open Terminal and Configure Tasks
Run and Select g++ build and debug activation file
9. The End
It was going to be very short at first but I skipped some details and wanted to continue without adding any extras. And the installation failed. I’ve also used the Dev C++ which is simpler option. But if you want to use VSCode you can do it this way.