title: C : Unix SDL2 library : undefined reference, issue in the Makefile?
body: <p>I'm looking to make a Makefile that can compile a C program on Unix (Ubuntu). That Makefile should include the SDL library (2.0), as well as SDL_image.</p>
  
  <p>So here's my current Makefile : </p>
  
  <pre><code>CC = gcc
  OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c))
  EXEC = main
  
  LDFLAGS = `sdl2-config --libs` -L/usr/lib -lSDL2_image
  CCFLAGS = `sdl2-config --cflags` -I/usr/include/SDL_image.h
  
  $(EXEC): $(OBJECTS)
      $(CC) $(LDFLAGS) $&lt; -o $@
  
  %.o: %.c
      $(CC) -c $(CCFLAGS) $&lt; -o $@
  
  .PHONY: clean
  
  clean:
      rm -f $(OBJECTS) $(EXEC)
  </code></pre>
  
  <p>And here's my current code (minimal code just to test the Makefile): </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;SDL.h&gt;
  #include &lt;SDL2/SDL_image.h&gt;
  
  int main(int argc, char **argv) {
  
      SDL_Window* window = NULL;
      SDL_Surface* screenSurface = NULL;
  
      if (SDL_Init(SDL_INIT_VIDEO) &lt; 0) {
          printf("Initialization error: %s\n",SDL_GetError());
          return 1;
      }
  
      window = SDL_CreateWindow("Test",SDL_WINDOWPOS_UNDEFINED,
      SDL_WINDOWPOS_UNDEFINED,640, 480,SDL_WINDOW_SHOWN);
  
      SDL_Quit();
      return 0;
  }
  </code></pre>
  
  <p>So when I write the command : make</p>
  
  <p>I get errors on all of the SDL functions.
  Here's an example : undefined reference to `SDL_Init'</p>
  
  <p>I have tried many things (such as different paths for the Include and Link in the Makefile), but nothing seems to work.</p>
  
  <p>So my question is : How can I solve theses undefined references to SDL2 functions ?</p>