C Development with VSCodium

The free and open-source IDE VSCodium does not support Microsoft’s extensions for C/C++ development due to their restrictive license. However, VSCodium can be configured to be suitable for convenient C development. The steps below have been tested on Linux Mint 22 in December 2024 for the C programming language, but can be easily adapted to the C++ programming language.

Setting Up the Development Environment

Installing the IDE VSCodium:

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

Installing the build tool CMake:

sudo apt install cmake

Linux Mint already comes with a sufficiently recent version of the GCC compiler. Alternatively, the Clang compiler can be installed:

sudo apt install clang

Start VSCodium either from the command line by calling codium or via the start menu.

Install these VSCodium extensions:

These extensions can be installed via the command line, even from within VSCodium’s built-in terminal:

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 new folder for the project (projects are called workspaces in VSCodium).

The workspace can be saved via the FileSave Workspace As… menu. The workspace file allows for easy opening of the project from the desktop’s file manager.

Add a new C source file main.c:

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

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

Add a new file called CMakeLists.txt in the workspace’s root folder; the code below creates a project called myprogram that compiles to an executable file myprogram:

cmake_minimum_required(VERSION 3.28.0)

project(myprogram LANGUAGES C)

# Create executable `myprogram` from the source file `main.c`.
# Multiple source files can 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)

In order to create debug and release builds in different directories, the line below has to be added to the workspace’s .vscode/settings.json file:

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

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

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

The build type (e. g., debug, release) can be selected in the status bar. The button with the gear icon builds the project, the button with the play icon runs it. Debugging can be started via the Run and Debug command of the activity bar on the left.

The programming language (argument -x) and C standard (argument -std) used by clangd for code checking, completion, etc. can be set on workspace level by adding a file .clangd to the workspace’s root directory:

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