# sdl2: Compiler throws “Undefined Reference”

I'm trying to learn computer graphics, but when I tried to get this very simple windower running with c

#include <stdio.h>
#include <stdlib.h>

#include <SDL2/SDL.h>

static const int width = 320;
static const int height = 180;

int main(int argc, char **argv)
{
SDL_Init(SDL_INIT_VIDEO);

SDL_Window *window = SDL_CreateWindow("Hello, SDL2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);

SDL_DestroyWindow(window);
SDL_Quit();

return 0;
}


I try to compile and...

vke@komputilo:~/dev/MiaLudo/source\$ gcc -g main.c -o ../ludo
/tmp/ccfVU5ua.o: In function main':
/home/vke/dev/MiaLudo/source/main.c:11: undefined reference to SDL_Init'
/home/vke/dev/MiaLudo/source/main.c:13: undefined reference to SDL_CreateWindow'
/home/vke/dev/MiaLudo/source/main.c:15: undefined reference to SDL_DestroyWindow'
/home/vke/dev/MiaLudo/source/main.c:16: undefined reference to SDL_Quit'
collect2: error: ld returned 1 exit status
`

Hoping someone can help me out, I'm running Trisquel Linux if that's important

• Being pedantic, the compilation looks fine, but you are getting a linker error. Presumably you'll need a "-l" (lower case L) linker option on the gcc line that points to the library that contains the SDL_xxxx functions. This, stackoverflow.com/a/17886993/626644 , suggests you need -lSDL (noting again the first char is a lowercase L) – Simon F Jun 18 at 8:09
• You might need to add a search path as well. (FWIW I've not used this library) – Simon F Jun 18 at 8:21