title: Very strange issue of makefile, No such file or directory
body: <p>I came across a very strange issue of makefile, here it is:
  System: Linux CentOS 6
  In the beginning, the name of makefile is “makefile”, its sample contents:</p>
  
  <pre><code>OPTFLAGS = -Wall -g -O
  CXX = g++ 
  INC = -I/usr/local/include -I/usr/include  
  LIBS = -L/usr/local/lib -L/usr/lib64    
  CXXFLAGS = $(OPTFLAGS) $(INC)
  
  SOURCES = file1.cpp file2.cpp file3.cpp
  OBJECTS = $(SOURCES:.cpp=.o)
  
  EXECUTABLE = mybin
  
  $(EXECUTABLE): $(OBJECTS) 
      $(CXX) $(CXXFLAGS) $(INC) $(LIBS) $(OBJECTS) -o $@
  
  file1.o : file1.cpp
  file2.o : file2.cpp
  file3.o : file3.cpp
  
  .PHONY: clean
  clean:
      rm -f $(EXECUTABLE) *.o core*
  </code></pre>
  
  <p>I got following err after I ran “make”:
   g++: file3.o: No such file or directory </p>
  
  <p>I have a workaround to add a dummy file after file3:</p>
  
  <pre><code>dummy.o : dummy.cpp
  </code></pre>
  
  <p>This way I could build successfully. </p>
  
  <p>And I know that I can delete all these lines:</p>
  
  <pre><code>file1.o : file1.cpp
  file2.o : file2.cpp
  file3.o : file3.cpp
  </code></pre>
  
  <p>let make to build using default settings, I could build successfully this way.</p>
  
  <p>I also tried to just rename “makefile” to “Makefile”, and with following lines without dummy line:</p>
  
  <pre><code>file1.o : file1.cpp
  file2.o : file2.cpp
  file3.o : file3.cpp
  </code></pre>
  
  <p>To my surprise, I could build successfully this way.</p>
  
  <p>Could anyone explain why I got error of “No such file or directory” for the last file3 in the beginning?</p>
  
  <p>Following is the error output:</p>
  
  <pre><code>g++ -g -Wall -O -I/usr/local/include -I/usr/include     -c -o file1.o file1.cpp
  g++ -g -Wall -O -I/usr/local/include -I/usr/include     -c -o file2.o file2.cpp
  g++ -g -Wall -O -I/usr/local/include -I/usr/include   -I/usr/local/include -I/usr/include   -L/usr/local/lib -L/usr/lib64 -lsybdb    file1.o file2.o file3.o -o mybin
  g++: file3.o: No such file or directory
  make: *** [mybin] Error 1
  </code></pre>
  
  <p>Following is the output after I added dummy line:</p>
  
  <pre><code>g++  -Wall -g -O -I/usr/local/include -I/usr/include     -c -o file1.o file1.cpp
  g++  -Wall -g -O -I/usr/local/include -I/usr/include     -c -o file2.o file2.cpp
  g++  -Wall -g -O -I/usr/local/include -I/usr/include     -c -o file3.o file3.cpp
  g++  -Wall -g -O -I/usr/local/include -I/usr/include   -I/usr/local/include -I/usr/include   -L/usr/local/lib -L/usr/lib64 -lsybdb    file1.o file2.o file3.o -o mybin
  </code></pre>
  
  <p>I tried to rename "makefile" to "Makefile" again, and it doesn't work this time.</p>