【问题标题】:How do I link and compile Raylib on windows?如何在 Windows 上链接和编译 Raylib?
【发布时间】:2021-11-06 11:40:25
【问题描述】:

我已经从官方来源安装了 raylib migw。安装目录为C:\raylib\raylib。我从网站上编写了示例程序,如下所示。

#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;
}

我使用gcc main.c -I C:\raylib\raylib\src 编译它,当我这样做时,我收到以下错误

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

我该如何解决这个问题?

【问题讨论】:

标签: c raylib


【解决方案1】:

将libraylib.a文件添加到lib文件夹中,然后运行以下命令

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-18
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 2011-05-27
    • 1970-01-01
    相关资源
    最近更新 更多