Search code examples
clinuxgccsdl

SDL 2 C Compiler Flags


Whenever I run the following, I get undefined references to all the SDL-related functions used in my program:

cc -lSDL2 -lGL *.o

I believe this is caused by the lack of -l linker flags.


Solution

  • To link to SDL and OpenGL:

    cc *.o -lSDL2 -lGL ...
    

    For Linux systems, you should use pkg-config:

    cc -c main.c $(pkg-config sdl2 --cflags)
    cc main.o $(pkg-config sdl2 --libs)
    

    (Make sure linker arguments like -l go after your source files)