在MAC上编译SDL

mrd*_*enz 2 c macos gcc sdl ffmpeg

#include "ffmpeg/libavcodec/avcodec.h"

#include "ffmpeg/libavformat/avformat.h"

#include "ffmpeg/libswscale/swscale.h"
#include "ffmpeg/libswscale/rgb2rgb.h"
#include "ffmpeg/libswscale/swscale_internal.h"

#include <stdio.h>

#ifdef __MINGW32__
#undef main /* Prevents SDL from overriding main() */
#endif

#include "SDL.framework/Headers/SDL.h"
#include "SDL.framework/Headers/SDL_thread.h"
Run Code Online (Sandbox Code Playgroud)

是使用此命令编译的:

gcc -o t1 tutorial01.c -lswscale -lavutil -lavformat -lavcodec -lz -lavutil -lm -framework SDL
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

Undefined symbols:
  "_main", referenced from:
      start in crt1.10.6.o
     (maybe you meant: _SDL_main)
ld: symbol(s) not found
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

从谷歌搜索,如果我尝试添加:#include"SDLMain.h"它有主要的动脉瘤.

kar*_*lip 5

将编译行更改为:

gcc -o t1 tutorial01.c -lswscale -lavutil -lavformat -lavcodec -lz -lavutil -lm `sdl-config --cflags --libs`
Run Code Online (Sandbox Code Playgroud)

在我的mbp上,sdl-config --cflags --libs输出:

-I/usr/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE
-L/usr/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa
Run Code Online (Sandbox Code Playgroud)