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_Window *window = SDL_CreateWindow("Hello, SDL2", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);


    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

  • $\begingroup$ 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) $\endgroup$ – Simon F Jun 18 at 8:09
  • $\begingroup$ You might need to add a search path as well. (FWIW I've not used this library) $\endgroup$ – Simon F Jun 18 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.