Wednesday, September 15, 2021

CLion + MinGW + Raylib + {fmt}

1. MinGW-w64

WINLIBS

1.1 Unzip archive to C:\mingw64 folder.

1.2 Add system environment variables:

PATH
C:\mingw64\bin

C_INCLUDEDE_PATH
C:\mingw64\include\

CPLUS_INCLUDE_PATH
C:\mingw64\include\; C:\mingw64\include\c++\11.2.0

LIBRARY_PATH
C:\mingw64\lib    

1.3 Check GCC version: gcc -v

1.4 Configure CLion Toolchains Settings

 

2. {fmt}

WWW

GITHUB

2.1 Download and unzip Source zipfile.

2.2 Open and compile in CLion as cmake project to static library.

2.3 Copy "libfmt.a" to C:\mingw64\lib

2.4 Copy "fmt" folder with headers to C:\mingw64\include


3. Raylib

WWW

GITHUB

3.1 Download and unpack "raylib-3.7.0_win64_mingw-w64.zip"

3.2  Copy static and dynamic libs "libraylib.a, libraylibdll.a" to C:\mingw64\lib for linking

3.3 Copy raylib.dll to C:\mingw64\bin for running

3.4 Copy header "raylib.h" to C:\mingw64\include

 

4. Make C++ project in CLion

4.1 Edit "CMakeLists.txt"

cmake_minimum_required(VERSION 3.20)
project(<target>)

set(CMAKE_CXX_STANDARD 20)

add_executable(<target> main.cpp)

target_link_libraries(<target> fmt raylibdll)

4.2 Edit "main.cpp"

#include <raylib.h>
#include <iostream>
#include <fmt/core.h>

int main(void) {

    InitWindow(800, 450, "raylib [core] example - basic window");

    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }

    CloseWindow();

    int x = 5;
    std::cout << fmt::format("x = {}", x);

    return 0;
}