0

问候

我对C非常陌生。我想知道使用raylib制作基本窗口的最少步骤/代码。我正在使用 Linux 并遵循 github https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux上的步骤,但老实说,我不知道从哪里开始构建我自己的项目。示例中的基本窗口是否需要 cmake 或 make:core_basic_window.c,我可以编译(使用来自 github 的说明,但我不确定如何修改/简化我自己项目的代码) . 谢谢 : )

我试图从 github pull/project/directory 复制并粘贴此代码并在其上运行 gcc,但我收到错误消息:

// Filename: core_basic_window.c

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

无法编译:

########-ThinkPad-T430:~/Documents/c/bin/tmp$ gcc core_basic_window.c
/usr/bin/ld: /tmp/ccB5BYug.o: in function `main':
blah.c:(.text+0x2d): undefined reference to `InitWindow'
/usr/bin/ld: blah.c:(.text+0x37): undefined reference to `SetTargetFPS'
/usr/bin/ld: blah.c:(.text+0x3e): undefined reference to `BeginDrawing'
/usr/bin/ld: blah.c:(.text+0x65): undefined reference to `ClearBackground'
/usr/bin/ld: blah.c:(.text+0xa6): undefined reference to `DrawText'
/usr/bin/ld: blah.c:(.text+0xab): undefined reference to `EndDrawing'
/usr/bin/ld: blah.c:(.text+0xb0): undefined reference to `WindowShouldClose'
/usr/bin/ld: blah.c:(.text+0xbc): undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
4

1 回答 1

0

你不喜欢你的图书馆。如果您使用的是 Notepad++ 选项,那么: 创建一个文件夹,然后创建一个 main.cpp/.c 文件。-> 导航到 Raylib 下载文件夹,当然解压缩,然后单击npp->then click notepad++.exe 在记事本++中单击文件->打开(或 Ctrl-O)然后导航到您为项目创建的文件夹->编写代码,然后单击 F6 运行。这应该很容易遵循说明。

编译器标志(用于 GCC)

echo > Setup required Environment
echo -------------------------------------
SET RAYLIB_PATH=C:\raylib\raylib
SET COMPILER_PATH=C:\raylib\w64devkit\bin
ENV_SET PATH=$(COMPILER_PATH)
SET CC=gcc
SET CFLAGS=$(RAYLIB_PATH)\src\raylib.rc.data -s -static -Os -std=c99 -Wall -I$(RAYLIB_PATH)\src -Iexternal -DPLATFORM_DESKTOP
SET LDFLAGS=-lraylib -lopengl32 -lgdi32 -lwinmm
cd $(CURRENT_DIRECTORY)
echo
echo > Clean latest build
echo ------------------------
cmd /c IF EXIST $(NAME_PART).exe del /F $(NAME_PART).exe
echo
echo > Saving Current File
echo -------------------------
npp_save
echo
echo > Compile program
echo -----------------------
$(CC) -o $(NAME_PART).exe $(FILE_NAME) $(CFLAGS) $(LDFLAGS)
echo
echo > Reset Environment
echo --------------------------
ENV_UNSET PATH
echo
echo > Execute program
echo -----------------------
cmd /c IF EXIST $(NAME_PART).exe $(NAME_PART).exe

如果您将其放入 main.bat 文件或其他文件中,它应该为您提供 raylib 运行时。

于 2022-01-09T22:39:49.413 回答