a bottom-up approach to c++ in vscode
I wanted to do this post for a long time. VsCode is largely made for 2 languages: Python, Javascript. The official guide does not say things in the way I like to describe things. It’s not bad, but just not intuitive to me because it uses a top-down approach instead of a bottom-up approach1. So here is a bottom-up approach to getting C++ working in VsCode.
I think of VsCode as a mini-operating system with a shell, editor, and daemon processes all-in-one. The editor is obviously that you can view files in real-time. The shell is able to interface with the operating system. The daemon processes render the graphics on the file that you are currently editing. The .vscode
is basically a shell configuration file that allows some scripting automation with the press of a button, similar to ~/.bashrc
or ~/.zshrc
. Installing those extensions adds the scripts and daemons which make coding in C++ significantly easier.
Only Python and Javascript come with build configurations baked into the program. For C++, install the “C/C++”, “C/C++ Extenstion Pack”,”CMake Tools” extensions by the author ms-vscode
. After doing so, you will need to reload the window using the VsCode Shell that is accessed thru “Cmd(Ctrl) + Shift + P” in MacOS(Windows). Then run the command “Python Debugger: Clear Cache and Reload Window”. You can also just exit VSCode and open it again. Verify that this step was completed correctly by confirming the bottom toolbar has the (Gear Symbol) Build, (Bug Symbol), (Play Symbol) options.
Now, one of the limitations to this guide is that it only supports CMAKE. I do believe that CMake is the best way to build packages with c++ because it is more readable than make. When you use the CMake Extension with vscode it automatically uses ninja to build, which uses a DAG2 to decide the build order more efficiently. Now when you click the gear icon, everything will be properly invoked which allows for easy debugging and running scripts.
DO NOT click on the items on the top right toolbar when editing a C++ file. Those are build systems linked to native building wihtout CMake.