这是生成文件:
生成文件.win
CC=gcc
CFLAGS=-Wall -ID:\dev\include -LD:\dev\lib -LD:\dev\bin
LIBS=-l mingw32 -l SDLmain -l SDL
TARGET=-mwindows
EXECUTABLE=main.exe
all:
$(CC) $(CFLAGS) $(LIBS) $(TARGET) main.c -o $(EXECUTABLE)
clean:
rm *o
(libSDL 和 libSDLmain 位于 D:\dev\lib 中。SDL.dll 位于 D:\dev\bin 中。)
这是代码
#include <SDL/SDL.h>
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
printf("Could not initialize!");
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE|SDL_DOUBLEBUF);
if (!screen) printf("Could not load video!");
int done = 0;
SDL_Event event;
while(!done)
{
while(SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
done = 1;
}
SDL_Flip(screen);
}
SDL_FreeSurface(screen);
printf("Exited cleanly");
return 0;
}
我用这个命令构建它:
mingw32-make -f makefile.win
并且 mingw32-make 将 makefile 转换为:
gcc -Wall -ID:\dev\include -LD:\dev\lib -LD:\dev\bin -l mingw32 -l SDLmain -l SD
L -mwindows main.c -o main.exe
没关系。
但后来我得到了所有这些迷人的错误:
main.c:(.text+0x42): undefined reference to `SDL_SetVideoMode'
main.c:(.text+0x7c): undefined reference to `SDL_PollEvent'
main.c:(.text+0x8b): undefined reference to `SDL_Flip'
main.c:(.text+0x9c): undefined reference to `SDL_FreeSurface'
collect2: ld returned 1 exit status
mingw32-make: *** [all] Error 1
所以,因为我正在与 mingw32、SDL 和 SDLmain 链接。我正在将目录添加到 SDL 标头中。为什么我会收到错误消息?