0

I am writing in C++ and using MinGW to compile. I copied and pasted this code from here into my raylib.cpp.

#include "raylib.h"

int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}

So when I compile it I type:

g++ -I"C:/path/to/raylib/src" raylib.cpp -o raylib.exe

Without the -I I receive errors about including "raylib.h", but when I do use it I get errors like:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0x33): undefined reference to `InitWindow'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0x3d): undefined reference to `SetTargetFPS'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0x42): undefined reference to `WindowShouldClose'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0x4e): undefined reference to `BeginDrawing'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0x76): undefined reference to `ClearBackground'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0xb7): undefined reference to `DrawText'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc3DNiLx.o:raylib.cpp:(.text+0xbc): undefined reference to `EndDrawing'
collect2.exe: error: ld returned 1 exit status

What can I do to make the "raylib.h" file not return undefined reference. I am only linking to the raylib/src folder and I made zero chances to that folder. What can I do?

Larson
  • 27
  • 4
  • 1
    You need to compile the raylib sources into a library first and link to that library. Simply setting the include path is not sufficient. See [the documentation](https://github.com/raysan5/raylib/wiki/Working-on-Windows) – Botje Aug 11 '20 at 22:42
  • You need to tell the compiler where to find the include file(s) with the `-I` flag (like you did), but you also need to tell the linker to link with the library with `-L"C:/path/to/raylib/src" -lraylib` – Brecht Sanders Aug 13 '20 at 10:29

0 Answers0