【问题标题】:Raylib undefined reference to functions on raspberry piRaylib 未定义对树莓派上的函数的引用
【发布时间】:2020-06-17 23:28:33
【问题描述】:

我正在努力学习 C,但我很难理解链接。我无法使用 raylib 库编译我的 main.c 文件。

生成文件

CFLAGS= -g -O -Wall -W -pedantic -std=c99 -O0
BASIC = -o -std=c99
LINKFLAGS=-I. -I/raylib/src -I../src -L/raylib/src  -L/opt/vc/lib -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl -DPLATFORM_RPI

run:
    gcc $(CFLAGS) $(LINKFLAGS) main.c -o main.o

main.c 文件

#include <stdio.h>
#include "raylib.h"

int main(void)
{
    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
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        BeginDrawing();

            ClearBackground(RAYWHITE);

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

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

    CloseWindow();        // Close window and OpenGL context 

    return 0;
}

目录结构

Pong/
  - main.c
  - Makefile
  - raylib/
  - raylib.h

但是当我运行 make && ./main.o 我得到这个错误。即使我有 raylib.h 文件并且我的项目中有 raylib 文件夹。有人知道会发生什么吗?

gcc -g -O -Wall -W -pedantic -std=c99 -O0 -I. -I/raylib/src -I../src -L/raylib/src  -L/opt/vc/lib -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl -DPLATFORM_RPI main.c -o main.o
/usr/bin/ld: /tmp/ccvCErhi.o: in function `main':
/home/pi/pong/main.c:12: undefined reference to `InitWindow'
/usr/bin/ld: /home/pi/pong/main.c:14: undefined reference to `SetTargetFPS'
/usr/bin/ld: /home/pi/pong/main.c:27: undefined reference to `BeginDrawing'
/usr/bin/ld: /home/pi/pong/main.c:29: undefined reference to `ClearBackground'
/usr/bin/ld: /home/pi/pong/main.c:31: undefined reference to `DrawText'
/usr/bin/ld: /home/pi/pong/main.c:33: undefined reference to `EndDrawing'
/usr/bin/ld: /home/pi/pong/main.c:18: undefined reference to `WindowShouldClose'
/usr/bin/ld: /home/pi/pong/main.c:39: undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status
make: *** [Makefile:6: run] Error 1

【问题讨论】:

    标签: c makefile raylib


    【解决方案1】:

    您必须将库放在链接行的末尾,在所有目标文件之后。此外,-I-D 是编译器标志而不是链接器标志:

    CFLAGS = -g -O -Wall -W -pedantic -std=c99 -O0 -I. -I/raylib/src -I../src -DPLATFORM_RPI
    
    LDFLAGS = -L/raylib/src -L/opt/vc/lib
    LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
    
    run:
            gcc $(CFLAGS) $(LDFLAGS) main.c -o main.o $(LDLIBS)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      • 2014-01-18
      • 2015-06-19
      • 1970-01-01
      相关资源
      最近更新 更多