title: How do I properly include libraries and header files in a Makefile?
body: <p>I am still new to programming in Linux with the GNU compilers and Makefiles. I'm trying to figure out how to compile all the header files and libraries with their respective object files.</p>
  
  <p>At first this was my Makefile:</p>
  
  <pre><code>all:
      g++  main.cpp
      g++ main.o -o game -lsfml-graphics -lsfml-window -lsfml-system
  </code></pre>
  
  <p>The files in my directory where:</p>
  
  <pre><code>main.cpp Window.h Game.h Makefile
  </code></pre>
  
  <p>All the methods where in the their header files. I would run make and it would compile. Then I moved all the methods in to their own .cpp files, so my directory would look like this:</p>
  
  <pre><code> main.cpp Window.h Window.cpp Game.h Game.cpp Makefile
  </code></pre>
  
  <p>So then I changed my Makefile to:</p>
  
  <pre><code>CC = g++
  CFLAGS = -std=c++11 -c -fpermissive
  LDLIBS = -lsfml-graphics -lsfml-window -lsfml-system
  SOURCES= main.cpp Window.cpp Game.cpp
  OBJECTS=$(SOURCES:.cpp=.o)
  EXECUTABLE=game
  
  
  all: $(SOURCES) $(EXECUTABLE)
  
  $(EXECUTABLE): $(OBJECTS)
      $(CC) $(OBJECTS) -o $@ $(LDLIBS)
  
  .cpp.o:
      $(CC) $(CFLAGS) $&lt; -o $@
  </code></pre>
  
  <p>I run make and get this:</p>
  
  <pre><code>Window.cpp:105:3: error: ‘m_windowTitle’ was not declared in this scope
     m_windowTitle, style);
     ^
  Window.cpp: In member function ‘void Window::Destroy()’:
  Window.cpp:110:2: error: ‘m_window’ was not declared in this scope
    m_window.close();
    ^
  Makefile:15: recipe for target 'Window.o' failed
  make: *** [Window.o] Error 1
  </code></pre>
  
  <p>Only when I include the SFML Graphics.hpp file in Window.h and Game.h can I compile correctly.</p>
  
  <p>Game.h:</p>
  
  <pre><code>#ifndef GAME_H
  #define GAME_H
  #include &lt;SFML/Graphics.hpp&gt;
  </code></pre>
  
  <p>Window.h:</p>
  
  <pre><code>#ifndef WINDOW_H
  #define WINDOW_H
  #include &lt;SFML/Graphics.hpp&gt;
  </code></pre>
  
  <p>Is that correct should I need to include the Graphics.hpp file in my other header files? And if so, why didn't I need to do it before?</p>