0

I'm trying to make a game with raylib.

I included the library

#include "raylib.h"

and included its include and lib files in g++

g++ -o ./bin/execute -I ./include -L ./lib ./main.cpp

but when i start using the raylib library, using an official example i get these errors at compilation:

/usr/bin/ld: /tmp/ccFEN46h.o: in function `main':
main.cpp:(.text+0x37): undefined reference to `InitWindow'
/usr/bin/ld: main.cpp:(.text+0x41): undefined reference to `SetTargetFPS'
/usr/bin/ld: main.cpp:(.text+0x48): undefined reference to `BeginDrawing'
/usr/bin/ld: main.cpp:(.text+0x70): undefined reference to `ClearBackground'
/usr/bin/ld: main.cpp:(.text+0xb1): undefined reference to `DrawText'
/usr/bin/ld: main.cpp:(.text+0xb6): undefined reference to `EndDrawing'
/usr/bin/ld: main.cpp:(.text+0xbb): undefined reference to `WindowShouldClose'
/usr/bin/ld: main.cpp:(.text+0xc7): undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status

How can I use the raylib library?

(my code):

#include "raylib.h"

int main(int argc, char const *argv[])
{
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "i like men");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            DrawText("Window moment (i like men btw)", 190, 200, 20, LIGHTGRAY);
        EndDrawing();
    }

    CloseWindow();

    return 0;
}
aw1lt
  • 24
  • 1
  • 4
  • 2
    `-I` and `-L` don't do anything by themselves. `-I` lets `#include` search custom directories, and `-L` lets `-l` search custom directories. You still need `-l` to link the libraries. – HolyBlackCat Oct 15 '22 at 15:01
  • @HolyBlackCat so what would i type to link raylib? – aw1lt Oct 15 '22 at 15:04
  • 1
    That I don't know. There should be a file named `lib??.a` in the `lib` directory, then you'd type `-l??`. This flag has to be to the right of any `.cpp`/`.o` files listed in the command. – HolyBlackCat Oct 15 '22 at 15:07
  • @aw1lt just search for the `.a` or `.lib` file and follow the instructions in the duplicate answers. – πάντα ῥεῖ Oct 15 '22 at 15:09
  • That project has very good documentation which gives your the install instructions and tells you how to link here: [https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) – drescherjm Oct 15 '22 at 15:35

0 Answers0