Skip to content
Jeffery Myers edited this page Oct 23, 2024 · 66 revisions

Building raylib on Windows

There are several ways to get setup on windows. This page will go through them from the easiest to the most difficult.

Compilers

For compilers on windows there are two popular choices.

Visual Studio

This is the industry standard IDE for working on windows. A free version is available as the community edition. https://visualstudio.microsoft.com/vs/community/ Note Visual studio is large and somewhat resource intensive, you should have a recently modern computer to use it.

MinGW-W64/GCC

This is an open source C/C++ toolchain that is very lightweight. The best way to get MinGW-W64 and GCC is via the W64Devkit https://github.com/skeeto/w64devkit/ Download the w64devkit zip file, unzip it and run W64Devkit.exe. that will give you a terminal that is ready to go.

Note that old MinGW (Not w64) from mingw.org will not work with raylib. You need to use MinGW-w64.

MSys2 Note We do not recommend using msys2 to get gcc, even though several tutorials suggest it. It can be difficult to configure properly and does not always include all the things needed for a complete development system. The W64-Devkit is a much better way to get the needed toolchain for building games with raylib.

Raylib-Quickstart, the simple solution to get started quickly.

The quickstart is a cross platform template for all desktop platforms that will setup raylib automatically.

https://github.com/raylib-extras/raylib-quickstart

It works with many compilers on windows, linux and Mac OS. Works with makefiles, visual studio, and VSCode.

Simply follow the instructions in that link and you will be done, you do not need to use the rest of this document.

Compile using Zig tools (cross platform)

This guide should work across all platforms, but the example is demonstrated on Windows.

  1. Download and unzip Raylib to a directory, e.g., C:\raylib.
  2. Place your C file in any desired location.
  3. Compile the C (i.e., test.c) file using the following command: zig cc -o test.exe test.c -I"C:\raylib\include" "C:\raylib\lib\libraylib.a" -lopengl32 -lgdi32 -lwinmm

Other methods

If you do not want to use the quickstart, you have several options

Manual Setup with W64Devkit

  1. Download w64devkit-x.xx.x.zip from https://github.com/skeeto/w64devkit

Unzip to c:\w64devkit

  1. Download raylib-5.0_win64_mingw-w64.zip from https://github.com/raysan5/raylib/releases

Unzip include and lib to c:\w64devkit\x86_64-w64-mingw32

https://github.com/skeeto/w64devkit?tab=readme-ov-file#library-installation

  1. Goto c:\w64devkit run w64devkit.exe,which launches a console

  2. Create raylibhelloworld.c

#include "raylib.h"

int main() {
  const int screenWidth = 800;
  const int screenHeight = 600;
  InitWindow(screenWidth, screenHeight, "Raylib basic window");
  SetTargetFPS(60);
  while (!WindowShouldClose()) {
    BeginDrawing();
    ClearBackground(RAYWHITE);
    DrawText("It works!", 20, 20, 20, BLACK);
    EndDrawing();
  }
  CloseWindow();
  return 0;
}
  1. Compile in w64devkit.exe console:

gcc -o raylibhelloworld.exe raylibhelloworld.c -lraylib -lgdi32 -lwinmm

  1. Run:

./raylibhelloworld.exe

Build raylib using make

Using MinGW make tool, just navigate from command line to raylib/src/ folder and type:

make

Installing and building raylib via vcpkg

You can download and install raylib using the vcpkg dependency manager:

  git clone https://github.com/Microsoft/vcpkg.git
  cd vcpkg
  bootstrap-vcpkg.bat
  vcpkg integrate install
  vcpkg install raylib

The default triplet in vcpkg is set to "x86-windows". If you want to install x64 version instead, you should use following command:

  vcpkg install raylib:x64-windows

The raylib port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

The instructions below are focused on compiling raylib using Notepad++ as the editor and TCC or MinGW as the compiler:

Build raylib using Notepad++ script

Just open raylib/src/raylib.h source file on Notepad++ and execute (F6) the script raylib_source_compile

A note on dependencies

Raylib includes all of it's own external dependencies on windows. There are only 2 system libraries that need to be linked to raylib for a game to work.

  • GDI32: This is the interface to the window setup and drawing functions that raylib and GLFW need to work on Windows.
  • WinMM: This is contains the high resolution timer code used by GLFW for precise timing in the game loop.

Building Examples

Build example using Notepad++ script

Just open your example source file on Notepad++ and execute (F6) the script raylib_compile_execute

Build ALL examples using make

Using MinGW make tool, just navigate from command line to raylib/examples/ folder and type:

mingw32-make PLATFORM=PLATFORM_DESKTOP

Build ONE example using gcc/g++

Open w64devkit.exe in C:\raylib\w64devkit then cd to c:/raylib/raylib/examples/core and type:

gcc core_basic_window.c -lraylib -lgdi32 -lwinmm

This will output a.exe to the current directory, where you can run it with ./a.exe.

Build ONE example using msvc/cl

cl gdi32.lib msvcrt.lib raylib.lib winmm.lib filename.c -Ic:\path\to\raylib\include /link /libpath:c:\path\to\raylib\lib /NODEFAULTLIB:libcmt

Install additional libraries in w64devkit

You can install C libraries by copying their files to 3 locations. Then you will be able to include the headers in your project files, and compile in w64devkit with the -l flag followed by the name of the installed library.

  • Copy headers (.h or .hpp) to C:\raylib\w64devkit\x86_64-w64-mingw32\include\
  • Copy libraries (.lib) to C:\raylib\w64devkit\x86_64-w64-mingw32\lib\
  • Copy executables (.dll or .exe) to C:\raylib\w64devkit\bin\

For example, after installing lua54.dll and lua54.lib (along with the headers), I was able to compile with gcc main.c -o mygame -lraylib -llua54 -lopengl32 -lgdi32 -lwinmm

Clone this wiki locally