C/C++ Dev. Environment using VS Code

One Ring to rule them all,
One Ring to find them,
One Ring to bring them all
and in the darkness bind them.

― J.R.R. Tolkien, The Fellowship of the Ring

Whether you are a Lord of the Rings movie fan or not, you will agree that uniformity appeals every one and having a unified development experience is something developers strive and welcome all the time. For a long time, development environment(s) have been tightly coupled with a particular technology e.g. visual studio for mostly .NET based development. We have seen heated debates among developers where they endlessly argue about one tool over another. This will never end and it shouldn’t because many times these arguments results in awesome tooling, which we are using today.

In this post, I will share with you a simple C/C++ development environment setup using VS Code. If you already using VS Code with some other programming language, then you are already half-way there. For others, they can check how the setup looks like and if they might wanna give it a try.

VS Code is a light-weight, open-source, free and extensible IDE and it is getting better every day. I use it frequently for my Node.js development work and in this post I will show you how easy it is start with C/C++ development using same IDE and have the similar experience.

Steps

  • Install Visual Studio Code (Typical Installation, download installer from this link)
  • Download and setup MinGW
  • VS Code C/C++ extensions setup

MinGW Setup

MinGW is a native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All of MinGW’s software will execute on the 64bit Windows platforms.

You can download MinGW installer from this link. Once downloaded you can double-click to start setup wizard. Also make sure that you are connected to internet.

You will be also asked to select the package, I selected the mingw g++ as follows. After selection from the menu, click Apply.

Once installation is done, you will find a folder on your C: drive name MinGW. There is a bin folder inside that and we need to include path to that bin folder to environment variable, so that later it can be found by VS code.

VS Code C/C++ extensions setup

From visual studio extensions tab, search for C/C++ extension and install it as follows:

Another handy extension, you wanna install is Code Runner. This extension will make it very easy for you to run your code.

After installing both extension, restart your VS-Code and we are all ready to write some C/C++.

Coding Part

Although this post is not about C/C++ programming itself, but here are few simple programs written in C and C++ to verify the code execution.

C code sample
C++ Code sample

You can click Play button (right-side) on your VS-Code editor (thanks to code runner extension) and check the following results.

Program execution

Temperature Conversion example code and its output.

Temperature-Conversion sample

Summary

VS Code can be used with various programming languages. I found using VS code very convenient for C/C++ development as well. Its not the only choice though but it is an easy one to setup and start with. Now, we have setup the tooling, we are ready to write some cool code and I will write some more posts about C/C++ programming in next posts. Till next time, Happy Coding.

References

  • https://code.visualstudio.com/docs/languages/cpp
  • sourceforge.net/projects/mingw/ (minGW installer)
  • https://www.youtube.com/watch?v=Ubfgi4NoTPk