C Development with VSCodium

How to configure and use the free, open-source IDE VSCodium for C development, including CMake project setup and compiler configuration.

Contents

Introduction

The free and open-source IDE VSCodium does not support Microsoft’s official C/C++ extensions due to their restrictive licensing. However, VSCodium can easily be configured into a powerful and convenient environment for C development. The steps below were tested on Linux Mint 22 in December 2024 for C, but they can be readily adapted for C++ development.

Setting Up the Development Environment

Installation of VSCodium

The repository is added and the IDE is installed by running the following commands in the terminal:

echo 'deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] \
  https://download.vscodium.com/debs vscodium main' | \
  sudo tee /etc/apt/sources.list.d/vscodium.list
sudo apt update && sudo apt install codium

Installation of Build Tools and Compilers

The CMake build system is installed via:

sudo apt install cmake

Linux Mint includes a recent version of the GCC compiler by default. Alternatively, the Clang compiler can be installed using:

sudo apt install clang

Installation of VSCodium Extensions

VSCodium can be launched either from the start menu or by executing codium in the terminal.

To enable C development features, the following extensions are required:

C/C++ Runner

Compiles, debugs, and runs C programs directly within VSCodium.

clangd

Provides code completion, navigation, and code insights.

CMake

Adds language support and syntax highlighting for CMake files.

CMake Tools

Integrates CMake build commands into the VSCodium interface.

CodeLLDB

Enables advanced debugging capabilities for C programs.

These extensions can be installed simultaneously via the terminal (or VSCodium’s built-in terminal) with the following commands:

codium --install-extension franneck94.c-cpp-runner
codium --install-extension llvm-vs-code-extensions.vscode-clangd
codium --install-extension twxs.cmake
codium --install-extension ms-vscode.cmake-tools
codium --install-extension vadimcn.vscode-lldb

Setting Up a C Project

In VSCodium’s Explorer sidebar, create a dedicated folder for the project (projects are called workspaces in VSCodium).

The workspace can be saved for future use via the FileSave Workspace As… menu command. Saving the workspace creates a .code-workspace file, which allows for the entire project to be reopened directly from the system’s file manager.

Create a new C source file named main.c:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Hello world!\n");
    return EXIT_SUCCESS;
}

Add a new file named CMakeLists.txt to the root directory of the workspace. The following configuration defines a project named myprogram, which compiles into an executable binary myprogram:

cmake_minimum_required(VERSION 3.28.0)

project(myprogram LANGUAGES C)

# Compile the source file `main.c` into the executable `myprogram`.
# Multiple source files may be listed, separated by spaces.
add_executable(
    myprogram
    main.c
)

# Use the C23 standard.
set_property(TARGET myprogram PROPERTY C_STANDARD 23)
set_property(TARGET myprogram PROPERTY C_STANDARD_REQUIRED ON)
set_property(TARGET myprogram PROPERTY C_EXTENSIONS OFF)

To isolate debug and release builds into separate directories, the following line has to be added to the workspace’s .vscode/settings.json file:

"cmake.buildDirectory": "${workspaceFolder}/build/${buildType}",

In the .vscode/launch.json file, the values for type, cwd, and program within the C/C++ Runner: Debug Session configuration have to be modified as follows:

"type": "lldb",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/build/Debug/myprogram",

The build variant (e. g., debug or release) is selectable via the status bar. The gear icon triggers the project build, while the play icon executes the binary. Debugging sessions are initiated via the Run and Debug command in the activity bar on the left.

The programming language (argument -x) and the C standard (argument -std) utilized by clangd for code analysis and completion can be configured globally for the workspace by adding a .clangd file to the workspace’s root directory:

CompileFlags:
  Add: [-xc, -std=c23]