iwrestledthebeartwice
iwrestledthebeartwice

Reputation: 734

How do I link and compile Raylib on windows?

I have installed the raylib migw from the official source. The installation directory is C:\raylib\raylib. I have written the sample program from the website as follows.

#include "raylib.h"

int main(void){
    const int screenWidth = 800;
    const int screenHeight = 600;

    InitWindow(screenWidth, screenHeight, "raylib basic window test");

    SetTargetFPS(60);

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

        EndDrawing();
    }

    CloseWindow();

    return 0;
}

I have compiled it using gcc main.c -I C:\raylib\raylib\src and when I do this, I'm getting the following error

C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x37): undefined reference to `InitWindow'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x43): undefined reference to `SetTargetFPS'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x48): undefined reference to `WindowShouldClose'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x58): undefined reference to `BeginDrawing'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x86): undefined reference to `ClearBackground'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0xce): undefined reference to `DrawText'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0xd3): undefined reference to `EndDrawing'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0xdd): undefined reference to `CloseWindow'
collect2.exe: error: ld returned 1 exit status

How do I fix this?

Upvotes: 3

Views: 12214

Answers (2)

hashir_gamer
hashir_gamer

Reputation: 1

create two folders 1)include 2)lib put raylib.h,raymath.h,rcamera.h,rlgl.h,util.h to include folder put lraylib.a file to lib folder and make main.c or main.cpp add the code that you have then go to w64devkit in c:\raylib\w64devkit run w64devkit.exe go to your solution directory in w64devkit cmd then type gcc -o raylibhelloworld.exe raylibhelloworld.c -lraylib -lgdi32 -lwinmm you should download raylib.zip frome the raylib github first the copy all the include files and lib files and also if you want to you can copy external header files from c:/raylib/raylib/src like rcamera.h,util.h

Upvotes: 0

iwrestledthebeartwice
iwrestledthebeartwice

Reputation: 734

Add libraylib.a file into lib folder, then run the following command

gcc main.c -o main -O1 -Wall -std=c99 -Wno-missing-braces -L ./lib/ -lraylib -lopengl32 -lgdi32 -lwinmm

Upvotes: 2

Related Questions