Installing SDL on OSX

前端 未结 4 1097
面向向阳花
面向向阳花 2021-01-16 02:30

I downloaded SDL2-2.0.3. I ran ./configure && make && make install.

I\'ve also tried brew install SDL2.

<
相关标签:
4条回答
  • 2021-01-16 03:13

    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)
    
    0 讨论(0)
  • 2021-01-16 03:16

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

    0 讨论(0)
  • 2021-01-16 03:27

    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
    
    0 讨论(0)
  • 2021-01-16 03:27

    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.

    0 讨论(0)
提交回复
热议问题