title: GNU make sometime doesn't search in folders declared in VPATH
body: <p>I'm trying to build a small C++ project with <em>GNU make</em> (version 3.81) but i must call <em>make</em> two times because the first run fails. This is my project directory:</p>
  
  <pre><code>project
      makefile
      include
          lexer.hpp   
      src
          main.cpp
          lexer.l
  </code></pre>
  
  <p>Following is my makefile:</p>
  
  <pre><code>CC = g++
  CPPFLAGS = -I include
  VPATH = include src
  
  OBJECTS = main.o lexer.o
  
  test: $(OBJECTS)
  $(CC) $(CPPFLAGS) -lfl -o $@ $^
  
  main.o: lexer.hpp main.cpp
      $(CC) -c $(CPPFLAGS) $^
  
  lexer.o: lexer.cpp
      $(CC) -c $(CPPFLAGS) $^
  
  lexer.cpp: lexer.l
      flex -t $^ &gt; src/lexer.cpp
  
  .PHONY: clean
  
  clean:
      rm -fR $(OBJECTS) src/lexer.cpp test
  </code></pre>
  
  <p>The first time i run <em>make</em> i get the following output where <em>make</em> complains about not finding the lexer.cpp file. But i don't understand why <em>make</em> don't seek in the folders declared in VPATH.</p>
  
  <pre><code>g++ -c -I include include/lexer.hpp src/main.cpp
  flex -t src/lexer.l &gt; src/lexer.cpp
  g++ -c -I include lexer.cpp
  g++: error: lexer.cpp: No such file or directory
  g++: fatal error: no input files
  compilation terminated.
  make: *** [lexer.o] Error 1
  </code></pre>
  
  <p>However if i call <em>make</em> again then lexer.cpp is found and the compilation works.</p>
  
  <pre><code>g++ -c -I include src/lexer.cpp
  g++ -I include -lfl -o test main.o lexer.o
  </code></pre>
  
  <p>Why?</p>
  
  <p>P.S. I apologize for poor english.</p>