Installing SDL on OSX

三世轮回 提交于 2019-12-01 13:54:46

You are failing to link with libSDL2.{a,dylib}.

You want:

gcc -o main main.c -lSDL2

or perhaps:

gcc -o main main.c -L/usr/local/lib -lSDL2

The following command is installed along with SDL and it tells you the correct switches for compiling and linking:

sdl2-config --cflags --libs

On my particular machine, that gives:

-I/usr/local/include/SDL2 -D_THREAD_SAFE
-L/usr/local/lib -lSDL2

That means you can compile and link like this and always be assured of getting the correct settings:

g++ main.cpp -o main $(sdl2-config --cflags --libs)

Or, you can put it in a Makefile like this (with a TAB at the start of the second line):

main:   main.cpp
        g++ main.cpp -o main $$(sdl2-config --cflags --libs)

You need to run

  • sdl2-config --cflags which will give you the compile flags, and
  • sdl2-config --libs which will give you the linker flags

needed for using SDL2.

The flags will vary by platform which is why you should use sdl2-config instead of hardcoding some specific flags into your Makefile or other build script.

Make sure you download the x64 SDL2 version. You also need to statically link it with -lSDL2 flag.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!