【问题标题】:Makefile Compilation for an SDL-dependant app fails miserably依赖 SDL 的应用程序的 Makefile 编译惨遭失败
【发布时间】:2012-07-25 16:40:13
【问题描述】:

这是生成文件:

ma​​kefile.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 标头中。为什么我会收到错误消息?

【问题讨论】:

  • 如果失败,不应该是Makefile.loose而不是Makefile.win吗?
  • @H2CO3 哈哈,不错。 :D

标签: c gcc makefile mingw sdl


【解决方案1】:

您应该将库标志放在最后:

gcc -o main.exe main.c -lSDL -lSDLmain -lmingw32

【讨论】:

  • @ApprenticeHacker 仅适用于较新版本的 GCC(阅读:是)。
猜你喜欢
  • 2018-04-25
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
  • 2012-03-30
  • 2020-05-15
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
相关资源
最近更新 更多