0

我正在用 C++ 编写并使用 MinGW 进行编译。我从这里复制并粘贴了这段代码到我的 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;
}

所以当我编译它时,我输入:

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

如果没有 -II 会收到有关包含“raylib.h”的错误,但是当我使用它时,我会收到如下错误:

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

我该怎么做才能使“raylib.h”文件不返回未定义的引用。我只链接到 raylib/src 文件夹,我对那个文件夹的机会为零。我能做些什么?

4

0 回答 0