C++ Project Setup Made Simple: Raylib, CMake, and VSCode Guide

C++ Project Setup Made Simple: Raylib, CMake, and VSCode Guide

Published: January 04, 2025 • Series: C++ Development • Level: beginner

c++ raylib cmake vscode setup beginner

This is Rambod and today we set up a complete C++ project environment with Raylib, CMake, and Visual Studio Code. This guide is designed for beginners who want a reliable workflow with the right tools and no wasted time.

1) Install the required tools

You will need:

After downloading:

  • Add CMake and Ninja to your system PATH.
  • Install vcpkg following the official documentation.
  • Verify installations in a terminal with commands:
    • cmake --version
    • ninja --version
    • vcpkg version

If they respond, everything is installed correctly.

2) Create your project folder

  • Make a new folder without spaces in its name, for example MyRaylibProject.
  • Right click → Open with VSCode.
  • Install the following VSCode extensions:
    • C++ IntelliSense
    • CMake Tools

Reload VSCode to finalize.

3) Initialize CMake in VSCode

  • Press Ctrl + Shift + P and search for CMake: Quick Start.
  • Enter your project name, for example MyRaylibCPPProject.
  • Choose Executable as the target.
  • Add a new preset and select your compiler toolchain.
  • Point CMake to the vcpkg toolchain file (found in vcpkg/scripts/buildsystems/vcpkg.cmake).
  • Save the preset.

4) Set up vcpkg dependencies

  • In your project root, create a file vcpkg.json.
  • Define project dependencies like this:
{
  "name": "my-raylib-project",
  "version-string": "0.1.0",
  "dependencies": [ "raylib" ]
}
  • Run vcpkg install to fetch and build Raylib.
  • CMake will automatically detect the package.

5) Update CMakeLists.txt

  • Set the minimum version, for example cmake_minimum_required(VERSION 3.21).
  • Add find_package(raylib CONFIG REQUIRED).
  • Use target_link_libraries(${PROJECT_NAME} PRIVATE raylib) at the end of the file.
  • Save changes.

6) Write your first Raylib program

Replace the default main.cpp with:

#include "raylib.h"

int main() {
    InitWindow(800, 600, "My Raylib Project");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Hello from Raylib!", 200, 280, 20, BLACK);
        DrawFPS(10, 10);
        EndDrawing();
    }

    CloseWindow();
    return 0;
}

This creates a window, displays text, and shows FPS.

7) Build and run

  • In VSCode, open the CMake Tools panel.
  • Select your preset and click Configure.
  • Then click Build.
  • If errors appear, delete cache and reconfigure.
  • Finally, run the project.

You should now see your Raylib window up and running.

8) Troubleshooting tips

  • If include errors appear, confirm that your vcpkg toolchain is set in the preset.
  • Use the correct architecture folder inside vcpkg (x64-windows or equivalent).
  • Reload VSCode if IntelliSense is not resolving Raylib headers.

Wrap up

You now have a complete C++ project setup with Raylib, CMake, and VSCode. This foundation makes it easy to expand with more libraries like SDL, ImGui, or fmt using the same workflow.

For more C++ tutorials and game dev tips, visit rambod.net, subscribe on YouTube, or watch this tutorial here: Watch on YouTube.