Writing C++ with Visual Studio Code on Windows 10
It’s a Friday evening and I’ve decided as always, to write some code. Since I haven’t worked with C++ for some time, I decided to try it out but there was a problem, I’m on Windows 10.
It took me few minutes to figure it out but I eventually managed to make the compiler properly work with my Visual Studio Code. Not to bore you too much, these are the steps you need to do to make your C++ compile properly.
- Download and install MinGW from Download MinGW. Make sure to select mingw32-gcc-g++ compiler (The GNU C++ compiler), mingw-developer-toolkit and mingw32-base
- Add MinGW to your PATH variable (C:\MinGW\bin)
- Install C++ plugin for Visual Studio Code.
- C/C++ for VS Code
- Like the above link stated, you must generate two files, c_cpp_properties.json and tasks.json.
- Your tasks.json should look something like this:
{ "version":"0.1.0", "command":"g++", "isShellCommand":true, "showOutput":"always", "args":[ "-g", "main.cpp" ] }
You can optionally compile your code from integrated VSC terminal (or any other) by typing g++ -g main.cpp
- In your c_cpp_properties.json, make sure to add a path to your your includes.
{
"name":"Win32",
"includePath":[
"${workspaceRoot}"
],
"defines":[
"_DEBUG",
"UNICODE"
],
"intelliSenseMode":"msvc-x64",
"browse":{
"path":[
"C:/MinGW/lib/gcc/mingw32/5.3.0/include/"
],
"limitSymbolsToIncludedHeaders":true,
"databaseFilename":""
}
}
- You are done. In case you are having issues compiling your code, make sure to restart your terminal and your VSC.