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
但是当我运行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,并且正在努力理解链接。我无法使用raylib库来编译main.c文件。生成文件CFLAGS = -g -O -Wall -W -pedantic -std = ...
-I
和-D
是编译器标志,而不是链接器标志: