Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Working on GNU Linux
raylib has several dependencies that you need in order to work with it.
You need aGCC (or alternative C99 compiler),make andgit (to download raylib repo).
sudo apt install build-essential gitYou need to install some required libraries;ALSA for audio,Mesa for OpenGL accelerated graphics andX11 for windowing system.
sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-devsudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomicrpm-ostree install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic
sudo dnf install libX11-devel libXrandr-devel libXi-devel libXcursor-devel mesa-libGL-devel pulseaudio-libs-devel libdrm-devel libXinerama-develsudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxineramasudo xbps-install make alsa-lib-devel libglvnd-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa MesaLib-develsudo xbps-install mesa-dri mesa-intel-dri
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.
To build your raylib game for GNU/Linux you need to download raylib git repository. raylib already comes with ready-to-use makefiles and CMake system to compile source code, examples and templates.
This guide is for all GNU/Linux distros, just note that APT is used as package manager for Debian based distros.
WARNING: Wayland building requires manual generation of some wayland specific files. GLFW support for Wayland is "experimental and incomplete". For more info check issue#2666
Building for wayland requires the following additional packages
sudo dnf install wayland-devel libxkbcommon-devel wayland-protocols-develTo build raylib for Wayland,-DGLFW_BUILD_WAYLAND=ON should be defined in the CMake step or passGLFW_LINUX_ENABLE_WAYLAND=TRUE as an argument to make.
You can compile three different types of raylib library:
- The static library (default method)
- The dynamic shared library
- The web library
If you are unsure about which one you should use, pick the static library.
Download the raylib repository fromGithub, then compile it with:
git clone --depth 1 https://github.com/raysan5/raylib.git raylibcd raylib/src/make PLATFORM=PLATFORM_DESKTOP # To make the static version.make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED # To make the dynamic shared version.make PLATFORM=PLATFORM_WEB # To make web version.Warning: if you want to compile a different type of library (static, ...), you must typemake clean before the compiling.
Install the library to the standard directories,usr/local/lib and/usr/local/include, or remove it:
sudo make install # Static version.sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.sudo make uninstallsudo make uninstall RAYLIB_LIBTYPE=SHAREDNOTE: raylib is configurable and can be be built in a variety of ways. Please readsrc/Makefile,src/config.h andraylib.h itself for a full listing of available options and values.
sudo apt install cmakeBuilding with cmake on Linux is easy, just use the following:
git clone https://github.com/raysan5/raylib.git raylibcd raylibmkdir build && cd buildcmake -DBUILD_SHARED_LIBS=ON ..makesudo make installsudo ldconfigIn case any dependencies are missing, cmake will tell you.
NOTE: raylib is configurable and can be be built in a variety of ways. See theCMake Build Options for a full listing of available options and values. Alternatively, you may use the curses UI provided byccmake(1) for interactively configuring raylib.
If you have installed raylib withmake install, Just move to the folderraylib/examples and run:
make PLATFORM=PLATFORM_DESKTOPIf raylib was installed withmake install RAYLIB_LIBTYPE=SHARED
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHAREDA more detailed command for the OpenGL ES GRAPHICS variant on Ubuntu 16.04 is:
make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGLES_20 RAYLIB_LIBTYPE=SHARED USE_EXTERNAL_GLFW=TRUE \ CFLAGS="-fPIC -I/usr/include/GL" LDFLAGS='-L/usr/local/lib/raysan5 -lGLESv2 -lglfw3'To compile just one specific example, add flags as needed:
make core/core_basic_window PLATFORM=PLATFORM_DESKTOPTo force recompile one example:
make core/core_basic_window PLATFORM=PLATFORM_DESKTOP -BTheraylib/games folder can be made the same way as the examples. Have fun!
Inraylib/examples run:
cmake -DCUSTOMIZE_BUILD=ON -DBUILD_EXAMPLES=ON ..makeInstead of using the embedded GLFW, you can download GLFW3 and build it from source (it requires CMake).
wget https://github.com/glfw/glfw/releases/download/3.2.1/glfw-3.2.1.zipunzip glfw-3.2.1.zipcd glfw-3.2.1cmake -DBUILD_SHARED_LIBS=ONsudo make installNow with GLFW installed, you may build raylib while specifyingUSE_EXTERNAL_GLFW:
make USE_EXTERNAL_GLFW=TRUE# orcmake -DUSE_EXTERNAL_GLFW=ONIf you are a packager for a Distribution not listed here, please take the time and create a raylib package.
openSUSE has raylib in the official repository. Install it via:
zypper in raylib-develUsers of older openSUSE versions will have to add thedevel:libraries:c_c++ devel project.
Add the repo, refresh sources and install raylib:
zypper ar -f http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_Factory/devel:libraries:c_c++.repozypper refzypper in raylib-develIf you have any doubt,just let me know.
Fedora hasraylib in the official repository.
raylib-devel- neededonly for development, installs runtime library tooraylib- runtime dependency for Fedora based systems
Continue with:
#> dnf install raylib-develContinue with:
#> dnf install raylibThe official Arch Repository contains theraylib package. Install via:
pacman -S raylibyum -y install devtoolset-9\*scl enable devtoolset-9 bashcd raylib/src/make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_11 -B- Begin by downloading the latest stable release of raylib into your project folder. Use the following commands:
cd your-project-foldermkdir externalwget https://github.com/raysan5/raylib/archive/refs/tags/5.5.tar.gz -P external/tar xvf external/5.5.tar.gz -C external/- Create a
flake.nixfile in the root folder of your project with the following content:
{description="Raylib development environment";inputs={nixpkgs.url="github:nixos/nixpkgs/nixos-unstable";};outputs={self,nixpkgs, ...}:letsystem="x86_64-linux";in{devShells."${system}".default=letpkgs=importnixpkgs{inheritsystem;};inpkgs.mkShell{packages=[pkgs.libGL# X11 dependenciespkgs.xorg.libX11pkgs.xorg.libX11.devpkgs.xorg.libXcursorpkgs.xorg.libXipkgs.xorg.libXineramapkgs.xorg.libXrandr# Uncomment the line below if you want to build Raylib with web support# pkgs.emscripten];# Audio dependenciesLD_LIBRARY_PATH=pkgs.lib.makeLibraryPath[pkgs.alsa-lib];};};}
- Create the development environment with the dependencies using:
nix develop
Or with nix channels
Alternatively, you can create ashell.nix file in the root folder of your project with the following content:
{pkgs ?import<nixpkgs>{}}:pkgs.mkShell{nativeBuildInputs=[pkgs.libGL# X11 dependenciespkgs.xorg.libX11pkgs.xorg.libX11.devpkgs.xorg.libXcursorpkgs.xorg.libXipkgs.xorg.libXineramapkgs.xorg.libXrandr# Web support (uncomment to enable)# pkgs.emscripten];# Audio dependenciesLD_LIBRARY_PATH=pkgs.lib.makeLibraryPath[pkgs.alsa-lib];}
Then, run the following command to enter the nix-shell:
nix-shell
- To build raylib, navigate to the src directory inside the external/raylib-5.5 folder and run make:
cd external/raylib-5.5/src/make PLATFORM=PLATFORM_DESKTOP- Now you can compile your project with raylib. The simplest possible Makefile for this would be:
RAYLIB ?= ./external/raylib-5.5/src/all: gcc src/main.c -I $(RAYLIB) -L $(RAYLIB) -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
After installing raylib from source or package manager, you can build a project with this command (modify as necessary):
cc game.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11Creating a Makefile will help with building as the project grows.
I get an error:error while loading shared libraries: libraylib.so.351: cannot open shared object file: No such file or directory after rebooting. Right after building the library it worked fine.
If you install raylib withRAYLIB_LIBTYPE=SHARED you may find that compiler is unable to locate library file. That is because raylib wasn't installed to standard system library directories. You can check in which directory raylib was installed by looking at themake install output:
<...>cp --update --verbose /home/<USERNAME>/<PATH_TO_RAYLIB>/raylib/libraylib.so.3.5.0 /usr/local/lib/libraylib.so.3.5.0<...>In this case raylib was installed to/usr/local/lib, but it can be that raylib gets installed into/usr/local/lib64 or some other directory. You should check the output yourself and make sure, that missing files are located in that directory.
Next all you need to do is either specify that install path in the makefile or set an environment variable. You can set an environment variable by typing:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib (replace/usr/local/lib with your install path)
You can append this command to the end of your~/.bashrc or~/.zshrc or other user login script, to make the change permanent. If you do so you'll be able to compile right away after you relogin. If you don't want to relogin just runsource <YOUR USER LOGIN SCRIPT>
For issues related like not able to link a library like libGL or libGLX in Void Linux, it's probably due to broken symlinks.
The broken symlinks could be checked using below command:
sudo xbps-pkgdb -a
The above command will output something similar to below one:
ERROR: MesaLib-devel: broken symlink /usr/lib/libGLX_mesa.so (target: /usr/lib/libGLX_mesa.so.0)ERROR: libglvnd-devel: broken symlink /usr/lib/libGL.so (target: /usr/lib/libGL.so.1)ERROR: libglvnd-devel: broken symlink /usr/lib/libGLESv1_CM.so (target: /usr/lib/libGLESv1_CM.so.1)ERROR: libglvnd-devel: broken symlink /usr/lib/libGLESv2.so (target: /usr/lib/libGLESv2.so.2)ERROR: libglvnd-devel: broken symlink /usr/lib/libGLX.so (target: /usr/lib/libGLX.so.0)ERROR: libglvnd-devel: broken symlink /usr/lib/libGLdispatch.so (target: /usr/lib/libGLdispatch.so.0)ERROR: base-files: unexistent file /etc/issueERROR: base-files: conf files check FAILED.This helps us to know which packages needs to be reinstalled to fix the broken symlink issus. From the above output, it's clear thatlibglvnd-devel,MesaLib-devel needs to be reinstalled.
One can you below command to reinstall these packages:
sudo xbps-install -f libglvnd-devel MesaLib-devel
The fastest way to get a game setup on with GCC, MinGW or Visual Studio is to use premake.
Seehttps://github.com/raylib-extras/game-premake for instructions
Or watch the video tutorial here
www.raylib.com | itch.io | GitHub | Discord | YouTube
- Architecture
- Syntax analysis
- Data structures
- Enumerated types
- External dependencies
- GLFW dependency
- libc dependency
- Platforms and graphics
- Input system
- Default shader
- Custom shaders
- Coding conventions
- Integration with other libs
- Working on Windows
- Working on macOS
- Working on GNU Linux
- Working on Chrome OS
- Working on FreeBSD
- Working on Raspberry Pi
- Working for Android
- Working for Web (HTML5)
- Working on exaequOS Web Computer
- Creating Discord Activities
- Working anywhere with CMake
- CMake Build Options
- raylib templates: Get started easily
- How To: Quick C/C++ Setup in Visual Studio 2022, GCC or MinGW
- How To: C# Visual Studio Setup
- How To: VSCode
- How To: Eclipse
- How To: Sublime Text
- How To: Code::Blocks