Raylib 未定义对 raspberry pi 上函数的引用
Raylib undefined reference to functions on raspberry pi
我正在努力学习 C,但我正在努力理解链接。我在使用 raylib 库编译 main.c 文件时遇到问题。
makefile
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
但是当我 运行 进行 && ./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
您必须将库放在 link 行的末尾,在所有目标文件之后。此外,-I
和 -D
是编译器标志而不是 linker 标志:
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)
我正在努力学习 C,但我正在努力理解链接。我在使用 raylib 库编译 main.c 文件时遇到问题。
makefile
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
但是当我 运行 进行 && ./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
您必须将库放在 link 行的末尾,在所有目标文件之后。此外,-I
和 -D
是编译器标志而不是 linker 标志:
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)