Issue
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
GCC arguments are positional, put the link flags after your o
files:
gcc *.o -lSDL2 -lGL
Also, if you're on a proper full Linux system I'd recommend using pkg-config
to pull compiler/linker flags:
gcc -c main.c `pkg-config sdl2 --cflags`
gcc main.o `pkg-config sdl2 --libs`
Answered By - genpfault