Raylib Setup in CLion with vcpkg

Raylib Setup in CLion with vcpkg

Raylib Setup in CLion with vcpkg

Setting up C++ libraries can be annoying. For beginners, it is often worse than writing the actual code. Headers are missing, libraries fail to link, CMake reloads with errors, and suddenly a simple game programming experiment turns into a build-system problem.

In this tutorial, you will set up Raylib inside CLion using vcpkg and CMake. The goal is to create a clean modern C++ workflow where CLion handles the IDE experience, CMake handles the build, vcpkg handles the dependency, and Raylib gives us a simple game-development library.

By the end, you will have a working Raylib project running inside CLion with a simple window and text rendered on screen.

Watch the video on YouTube: CLion Just Made Raylib Setup Too Easy

Subscribe for more C++ and game development tutorials: Rambod YouTube Channel

What You Will Build

  • A new C++ project in CLion
  • A working CMake configuration
  • Raylib installed through vcpkg
  • A minimal Raylib Hello World window
  • A clean project setup you can reuse for future C++ game prototypes

This tutorial is designed for beginners, students, indie developers, and anyone who wants a clean Raylib setup without manually downloading libraries and fighting include paths.

Why CLion, CMake, and vcpkg Work Well Together

This stack makes sense because each tool has a clear job.

  • CLion gives you the IDE, debugger, code analysis, CMake integration, and project navigation.
  • CMake defines how the C++ project is configured and built.
  • vcpkg installs and manages third-party C and C++ libraries.
  • Raylib gives you a simple game-development library for windows, input, drawing, audio, and basic 2D or 3D experiments.

The biggest advantage is that you do not manually copy Raylib headers and binaries around your system. You install Raylib through vcpkg, let CMake find it, then link it to your executable.

That is the workflow you want. Manual C++ library setup is where beginners waste days.

CLion Free for Non-Commercial Use

JetBrains announced that CLion is free for non-commercial use, which makes it much more accessible for hobby developers, students, and indie experimentation. That matters because CLion is a professional C and C++ IDE with strong CMake support, code completion, refactoring, debugging, and built-in package-management tools. :contentReference[oaicite:1]{index=1}

If you are building commercial software, check JetBrains licensing carefully. But for learning, prototyping, personal projects, and non-commercial experiments, CLion has become much easier to recommend.

Why Use Raylib?

Raylib is a great library for learning game programming because it is simple and direct. You do not need to understand a massive game engine before you can open a window, draw shapes, handle input, and start building small game systems.

Raylib is useful for:

  • learning C++ game programming
  • building small 2D games
  • making quick prototypes
  • testing math, input, collision, and rendering ideas
  • creating simple tools or visual experiments
  • understanding the game loop without engine bloat

If Unreal Engine is too heavy for what you are testing, Raylib is a good lightweight alternative.

Step 1: Install CLion

Download CLion from JetBrains:

CLion official website

Install it for your operating system. CLion supports Windows, macOS, and Linux.

During first setup, CLion will try to detect your compiler toolchains and CMake configuration. If it cannot detect them automatically, you will need to configure them manually.

Step 2: Choose the Right Compiler Toolchain

On Windows, you usually have three common compiler options:

  • MSVC, through Visual Studio or Build Tools
  • MinGW, a GCC-based Windows toolchain
  • Clang, through LLVM

All three can work, but they are not the same.

MSVC

MSVC is the safest choice if you mostly build Windows-native projects and want strong compatibility with Visual Studio-style C++ workflows.

MinGW

MinGW is lightweight and popular for simple C++ setups. It can work well with Raylib, especially for beginner projects.

Clang

Clang is a strong cross-platform compiler choice and is useful if you care about similar behavior across macOS, Linux, and Windows.

Brutal advice: if you are a beginner on Windows and you do not know what to choose, start with MSVC or MinGW. Do not overthink it. Get the project running first.

Step 3: Configure the Toolchain in CLion

Open CLion settings:

Settings > Build, Execution, Deployment > Toolchains

CLion will show detected toolchains. Choose the one you want to use and move it to the top if needed.

Make sure CLion detects:

  • C compiler
  • C++ compiler
  • Debugger
  • CMake
  • Build tool

If any of these are missing, fix the toolchain before you continue. Raylib setup will not work properly if your compiler setup is broken.

Step 4: Create a New C++ Project in CLion

Open CLion and create a new project.

Choose a normal C++ executable project and name it something like:

RambodDevRaylib

For the C++ standard, you can use:

C++23

C++17 is also fine for Raylib, but C++23 is a good default if your compiler supports it.

CLion will create a starter main.cpp and CMakeLists.txt.

Step 5: Open the vcpkg Tool Window

CLion includes vcpkg integration for CMake projects, which helps you browse, install, and manage C++ packages directly from the IDE. JetBrains documents vcpkg support as available for CMake projects, with limitations for some other project formats and toolchains. :contentReference[oaicite:2]{index=2}

Open:

View > Tool Windows > vcpkg

If the vcpkg tool window is not already configured, you need to add a vcpkg repository.

Step 6: Add a vcpkg Repository in CLion

Inside the vcpkg tool window, click the plus button to add a repository.

Configure:

  • Name: something like vcpkg classic
  • Repository URL: the default Microsoft vcpkg GitHub URL is fine for most users
  • Directory: where CLion should clone or use vcpkg

Enable the options that add vcpkg integration to your current CMake profiles and Debug builds.

Once the repository is active, CLion can use it to install packages like Raylib.

Step 7: Search for Raylib in vcpkg

In the vcpkg tool window, search for:

raylib

Select the package and click Install.

vcpkg will download and build Raylib and any required dependencies. The first install may take a little time depending on your machine and compiler.

Do not close CLion in the middle of this process. Let it finish.

Step 8: Update CMakeLists.txt

After installing Raylib, CLion or vcpkg may suggest the CMake lines needed to use it.

Your CMakeLists.txt should look like this:

cmake_minimum_required(VERSION 3.26)

project(RambodDevRaylib)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(RambodDevRaylib main.cpp)

find_package(raylib CONFIG REQUIRED)

target_link_libraries(RambodDevRaylib PRIVATE raylib)

The important parts are:

  • add_executable creates your program target.
  • find_package(raylib CONFIG REQUIRED) asks CMake to locate Raylib through vcpkg.
  • target_link_libraries links Raylib to your executable.

Make sure the target name in target_link_libraries matches the name inside add_executable. If your project is named differently, update the CMake file.

Important CMake Note

If your executable target is named:

RambodDevRaylib

then this line must also use:

target_link_libraries(RambodDevRaylib PRIVATE raylib)

If you accidentally write a different target name, CMake will fail because it cannot link a library to a target that does not exist.

This is one of the most common beginner mistakes.

Step 9: Reload CMake

After editing CMakeLists.txt, reload CMake in CLion.

If the first reload fails, do not instantly panic. Sometimes CLion needs another reload after package installation or toolchain updates.

Try:

  • Reload CMake
  • Wait for vcpkg package setup to finish
  • Reload again if needed
  • Check that the correct toolchain is selected
  • Check that the target name matches

If it still fails, read the exact error. Guessing randomly is how people waste an hour.

Step 10: Write the Raylib Hello World Code

Open main.cpp and replace the starter code with:

#include "raylib.h"

int main()
{
    InitWindow(800, 600, "Hello Raylib");

    SetTargetFPS(60);

    while (!WindowShouldClose())
    {
        BeginDrawing();

        ClearBackground(RAYWHITE);

        DrawText("Hello World from Raylib + CLion!", 170, 280, 20, BLACK);

        EndDrawing();
    }

    CloseWindow();

    return 0;
}

This is the smallest useful Raylib test. It opens a window, clears the background every frame, draws text, and closes cleanly when the window should close.

Understanding the Code

Include Raylib

#include "raylib.h"

This gives your C++ file access to Raylib functions like InitWindow, DrawText, and CloseWindow.

Create the Window

InitWindow(800, 600, "Hello Raylib");

This creates an 800 by 600 window with the title “Hello Raylib”.

Set the Frame Rate

SetTargetFPS(60);

This asks Raylib to run the loop at 60 frames per second. For beginner projects, this makes behavior easier to read.

Main Game Loop

while (!WindowShouldClose())
{
    BeginDrawing();
    ClearBackground(RAYWHITE);
    DrawText("Hello World from Raylib + CLion!", 170, 280, 20, BLACK);
    EndDrawing();
}

This loop runs until the player closes the window. Inside the loop, Raylib starts drawing, clears the background, draws text, and ends the frame.

Close the Window

CloseWindow();

This releases the window and closes Raylib properly.

Step 11: Build and Run

Click Build in CLion, then Run.

If everything is configured correctly, you should see a Raylib window with the text:

Hello World from Raylib + CLion!

At this point, the setup works. You now have a clean C++ Raylib project managed through CLion, CMake, and vcpkg.

Common Problem: CLion Cannot Find Raylib

If CLion cannot find Raylib, check these first:

  • Did Raylib install successfully in the vcpkg tool window?
  • Did you add vcpkg integration to the CMake profile?
  • Did you reload CMake after installing Raylib?
  • Is your selected toolchain supported by CLion’s vcpkg integration?
  • Does your CMakeLists.txt include find_package(raylib CONFIG REQUIRED)?

Do not start changing random compiler settings before checking these basics.

Common Problem: CMake Target Name Is Wrong

If your CMake file says:

add_executable(MyGame main.cpp)

then your link line must use:

target_link_libraries(MyGame PRIVATE raylib)

Not:

target_link_libraries(RambodDevRaylib PRIVATE raylib)

unless your target is actually named RambodDevRaylib.

Target names must match. CMake is strict about this, and it should be.

Common Problem: CMake Reload Fails After Installing Raylib

If CMake reload fails right after installing Raylib, try a second reload after the install completes.

If that does not work:

  • clear the CMake cache
  • reload the project
  • check the selected CMake profile
  • confirm the vcpkg repository is active
  • confirm the selected compiler matches the installed vcpkg package triplet

Most CMake problems here come from toolchain mismatch or incomplete reload, not from Raylib itself.

Why This Workflow Is Better Than Manual Setup

Manual Raylib setup usually means downloading files, adding include directories, linking libraries, fixing platform-specific dependencies, and repeating the same pain every time you create a new project.

With this workflow:

  • CLion manages the project experience
  • CMake defines the build
  • vcpkg installs Raylib
  • your CMake file links Raylib cleanly

This is closer to how serious C++ projects should be structured.

What to Build Next

After Hello World works, do not stop there. Build a small project immediately while the setup is fresh.

Good next steps:

  • draw a moving rectangle
  • handle keyboard input
  • add delta time movement
  • load a texture
  • play a sound
  • create a simple player class
  • organize the code into folders
  • build a small arcade prototype

The fastest way to learn Raylib is to build small things, not stare at setup screens forever.

Conclusion

In this tutorial, you created a clean Raylib setup in CLion using vcpkg and CMake. You configured the compiler toolchain, added a vcpkg repository, installed Raylib, updated CMakeLists.txt, reloaded CMake, and ran a working Raylib Hello World project.

This gives you a strong starting point for C++ game development without manually hunting headers and libraries.

Watch the full tutorial on YouTube: CLion Just Made Raylib Setup Too Easy

Subscribe for more C++ and game development tutorials: Subscribe to Rambod on YouTube

Resources

Frequently Asked Questions

Is CLion free?

CLion is free for non-commercial use according to JetBrains’ announcement. For commercial work, check the current JetBrains licensing terms.

Can I install Raylib directly from CLion?

Yes. CLion integrates with vcpkg for CMake projects, so you can search and install packages like Raylib from the vcpkg tool window.

Which compiler should I use for Raylib on Windows?

MSVC and MinGW are both reasonable beginner choices. MSVC is strong for Windows-native development, while MinGW is lightweight and commonly used in simple C++ setups.

Why does CMake fail after I install Raylib?

Common reasons include a wrong target name, missing vcpkg integration, wrong toolchain selection, or CMake needing a reload after package installation.

Do I need CMake for Raylib?

You can use Raylib without CMake, but for CLion, CMake is the cleanest and most practical workflow.

Is Raylib good for learning C++ game development?

Yes. Raylib is lightweight, direct, and beginner-friendly, making it a strong choice for learning game loops, input, drawing, and simple 2D game systems.

Rambod Ghashghai

Rambod Ghashghai

Technical Director & Unreal Engine Educator

Senior systems architect and Unreal Engine technical educator with 11+ years of enterprise infrastructure experience. Director of IT at Tehran Raymand Consulting Engineers and creator of Rambod Dev.

Full profile

Related Tutorials

More lessons connected by category, tags, engine version, or implementation type.

What To Do Next

Keep exploring practical Unreal Engine and systems programming work.

Recommended resource

Recommended for this tutorial

Useful tools selected for this workflow topic.

Share this page

Send it to your network in one tap.

Instagram doesn’t provide direct web share links. We copy your URL and open Instagram.