Hi there,
Since it’s my first post lets start with compiling the thing on linux, WHY? Simple, because on windows it’s already done lol. You can get the lib and includes pre-compiled but they might have dependencies errors (version related) similar to CLIB 2.28 or other bs. (I might be wrong also).
You might get some error messages about the CMAKE version 3.28…Go to the freaking CMakeLists.txt file and change the required version to the same as your system (my case was 3.22) and the compilation will run smoothly.
cmake_minimum_required(VERSION 3.28)
#this change avoid the warning that appear when we include raylib using Cmake fatch content
project(raylib)
Just change to…
cmake_minimum_required(VERSION 3.22)
#this change avoid the warning that appear when we include raylib using Cmake fatch content
project(raylib)
Now you can move those sexy files to your IDE or whatever. I use QtCreator since I’m not a chad coder.
There might be easier wais to do it, but I’m dumb and I love QtCreator IDE and setting things on CMAKE in the lamest way possible..
- set up your project on QtCreator (non qt / Plain C Application).
- move your include directory and libraylib.a to somewhere in your application directory:
/GAME_RAYLIB_6/vendor/linux/raylib - set up your CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(GAME_RAYLIB_6 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
#output directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
add_executable(GAME_RAYLIB_6 src/main.c)
if(UNIX)
# add raylib
find_library(LIB_RAYLIB raylib ${CMAKE_SOURCE_DIR}/vendor/linux/raylib)
if(NOT LIB_RAYLIB)
message(${CMAKE_SOURCE_DIR}/vendor/linux/raylib)
message(FATAL_ERROR "raylib library not found")
endif()
# ----- INCLUDES ----
include_directories(
${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/vendor/linux/raylib/include
)
target_link_libraries(${PROJECT_NAME} ${LIB_RAYLIB} m X11)
endif()
- put some test code in your project:
#include <stdio.h>
#include "raylib.h"
int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
As you can see, I do not have any intention to show this as a proper tutorial, it’s just for my future reference… Have a great day!
Leave a Reply