Skip to content

Setting Up a Visual Studio Code IDE

Kyra Stovicek edited this page Jun 4, 2026 · 6 revisions

Previous: Getting Started

For mahi-lib based projects, we recommend using a lightweight text editor over full blown IDEs like Visual Studio or Eclipse. While these IDEs provide a number of features which are undoubtedly useful, it's is unlikely that you will benefit from the added complexity. Furthermore, it is very easy for your projects to become tightly integrated with the IDE itself, making future migrations difficult.

We recommend using Visual Studio Code (not to be confused with Visual Studio proper). VS Code is similar to text editors like Sublime and Atom, but provides a number of features and extensions which make it well suited for small scale CMake based C++ development.

Start by downloading VS Code:

> choco install vscode

Go ahead and download the Ninja too if you don't already have it. This will make the integrated CMake experience better later on when we install the CMake Tools extension.

> choco install ninja

Now open VS Code! We recommended watching these introductory videos before continuing.

Required Extensions

There are three extensions you will need to develop effectively for C++:

  1. C/C++ - Extension from Microsoft offering code completion, IntelliSense, debugging, etc. (documentation)

Note: For projects interfacing with CadADi, you need to use version 1.22.11 or earlier. I'd recommend turning off Auto Update to ensure this does not change without your knowledge.

  1. CMake Tools - Extension which integrates CMake with VS Code and C/C++ extension (documentation) Note: For projects interfacing with CadADi, you need to use version 1.19.52 or earlier. I'd recommend turning off Auto Update to ensure this does not change without your knowledge.

  2. CMake - A simple syntax highlighter for CMake files

extensions

You may also choose to install a new theme. Good options include Dracula Official, One Dark Pro, and Material Theme.

mahi-template usage

The mahi-template is already configured to work with VS Code and the installed extensions. Make a local copy of the template anywhere you like and open the folder in VS Code. The main areas of interest are:

extensions
  • CMake Tools - A sidebar badge for the extension from which you can Configure, Build, Clean, etc. your project.
  • Variant - The CMake Tools Variant currently selected. Controls what configuration options are passed to CMake. Click to choose other options. The template defines two variants by default:
    • Release - the binaries are optimized for size and speed
    • Debug - the binaries are not optimized and include embedded Debugging information
  • Kit - The CMake Tools Kit currently selected. Controls which compiler or toolchain CMake is told to generate files for. Click to choose other options. The one you will likely use is Visual Studio Community 2019 Release - amd64 which is the 64-bit MSVC compiler.
  • Build - Builds a selected target ([all] by default, but could be a single library/executable if your project defines multiple targets)
  • Debug - Debugs a selected target displaying pertinent info in the Debug sidebar on the left (Bug Icon). You'll want to have the Debug Variant selected when debugging.

The template Variants and Kits are can be defined in two files in the .vscode folder: cmake-kits.json and cmake-variants.yaml. It is not required to use these files, but feel free to expand the Variants as your CMake project options grow.

You're now ready to start developing mahi-lib based apps! From VS Code you have everything at your fingertips, and should no longer have to execute CMake commands from the terminal. Finally note that a handful of useful CMake Tools commands can be accessed via the command palette with Ctrl+Shift+P and by typing "cmake".

Clone this wiki locally