Setting up VSCode for Windows C/C++ development
There has been an eternal debate over which IDE is the best for software development. But over the years, my stance on this issue has just been one. The best IDE is the one that helps to get the job done. I mostly use Microsoft Visual Studio for software development in my day job and it works just fine. It has many features that I take advantage of during development. However with great power comes great responsibility, therefore that same IDE runs like a honking mess on my personal computer (Don't come at me, I use a lowly Intel Core i3-based Lenovo L440 laptop from 2012). Because of that, I prefer using the light alternative Visual Studio Code for my projects. It doesn't have as many features as Visual Studio but then again my projects are not Gigabytes of enterprise-grade code that I need to comb through when I need to make a change. Visual Studio Code being a bare-bones editor for development, there is quite some setting up that needs to be done and this guide is meant to help you to do just that. The following steps are a comprehensive guide on how to set up VSCode for C++ development.
You need a compiler
You need a compiler to convert your code from just text to binaries. I use mingw-gcc for my Windows C/C++ development. I don't have any special reason why I use that, I just prefer it over other compilers. Installing the mingw-gcc compiler is simple, you can download the installer from mingw-w64.org and install it to an appropriate directory on your primary hard drive.
After downloading and installing the compiler we then need to add its directory to the Windows system environment variables. Search for ‘Environment variables’ in your Windows search bar or navigate to ‘Settings -> Advanced System Settings -> Environment Variables’. Adding the directory of mingw-gcc to your system variables allows you to run the various gcc commands you need to build binaries from C/C++ code.
You can check the versions of the mingw tools by running the following commands (This is also a check for whether everything is set up properly):
gcc -v
g++ -v
gdb -v
If any of these commands return an error as an output, you might need to go over your setup again to verify if you have not missed any step. You can refer to.
We can then proceed to set up VSCode for C/C++ development. If you don't have VSCode, you can download and install it from here.
Installing The Required Extensions
After installing VSCode, open it up and go to the extensions tab on the left pane. Search for the Microsoft C/C++ Extensions pack and install it. The Microsoft C/C++ extensions pack contains a lot of features that will supercharge your software development.
After installing the Microsoft C/C++ extensions, you can proceed to write a simple hello world app and run it.
If everything is set up correctly and you can run the hello world app correctly, then you are already set to start programming in C/C++ in your VSCode editor! Happy Coding!