title: g++ - not reflecting changes made in source file
body: <p>I'm building a project with a structure like this:</p>
  <pre><code>- Makefile
  - main.cpp
  - util.h
  - subsrc/
    - one.cpp
    - two.cpp
  </code></pre>
  <p>And I have my Makefile set up to output to a build directory:</p>
  <pre><code>all: $(BIN_FILE)
  
  $(BIN_FILE): $(OBJ_FILES)
      mkdir -p $(BIN_DIR)
      g++ $^ -o $@
  
  $(OBJ_DIR)/%.o: %.cpp
      mkdir -p $(OBJ_DIR)
      g++ -c $^ -o $@
  
  $(OBJ_DIR)/subsrc/%.o: subsrc/%.cpp
      mkdir -p $(OBJ_DIR)/subsrc
      g++ -c $^ -o $@
  
  clean:
      rm -rf $(BUILD_DIR)/*
  </code></pre>
  <p>However, I'm seeing this issue when I run g++ manually as well, so I don't think it's related to the Makefile.</p>
  <p>I can build from clean and everything works fine. The issue is when I change one of the subsrc files and try to recompile, via <code>make</code> or by running these commands myself:</p>
  <pre><code>g++ -c subsrc/one.cpp -o build/obj/subsrc/one.o
  g++ build/obj/main.o build/obj/subsrc/one.o build/obj/subsrc/two.o -o build/bin/prog
  </code></pre>
  <p>If I do this, changes made in <code>one.cpp</code> are <strong>not reflected</strong> in the binary output. If I recompile <code>main.cpp</code> (or, of course, the entire project), it works fine. This is not an issue of g++ not properly overwriting files, since even if I <code>rm build/obj/subsrc/one.o</code> and/or <code>rm build/bin/prog</code> before running the above commands, I still don't see the changes. That makes no sense to me and I have no idea what's happening.</p>
  <p>EDIT: I have uploaded a minimum reproducible example here. <a href="https://github.com/scatter-dev/so_70242118_min_repro" rel="nofollow noreferrer">https://github.com/scatter-dev/so_70242118_min_repro</a></p>
  <p>Reproduction instructions:</p>
  <ol>
  <li>Build using <code>make</code> or by running the g++ commands above.</li>
  <li>Run the program to ensure it has built correctly.</li>
  <li>Change the output of the <code>doWork</code> function in <code>one.cpp</code>. Save to disk.</li>
  <li>Rerun <code>make</code> and note that the <code>one.o</code> file is recompiled and <code>prog</code> is recreated with the linker.</li>
  <li>Run the program again and see that the output has not changed.</li>
  </ol>
  <p>At the suggestion of a commenter, I checked the md5sum of <code>one.o</code> and <code>prog</code> between steps 1 and 4 and they are indeed both the same. This remains the case <strong>even if I delete <code>one.o</code> before recompiling</strong>. Yes, I am sure that <code>one.cpp</code> is being saved to disk (its md5sum does change, along with the fact that <code>make clean &amp;&amp; make</code> will compile using the new changes).</p>