这是makefile:
makefile.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标头中。为什么我会收到错误?
答案 0 :(得分:3)
您应该将库标志放在最后:
gcc -o main.exe main.c -lSDL -lSDLmain -lmingw32