title: Understanding the origin of a linker duplicate symbol error
body: <p>I have a c++ program that compiled previously, but after mucking with the Jamfiles, the program no longer compiled and <code>ld</code> emitted a <code>duplicate symbol error</code>. This persisted after successively reverting to the original Jamfiles, running <code>bjam clean</code>, removing the objects by hand, and switching from clang with the gcc front end to gcc 4.2.1 on MacOs 10.6.7. </p>
  
  <p>A simplified description of the program is that there is <code>main.cpp</code> and four files, <code>a.h,cpp</code> and <code>b.h,cpp</code>, which are compiled into a static library which is linked to <code>main.o</code>. Both, <code>main.cpp</code> and <code>b.cpp</code> depend on the file containing the offending symbol, <code>off.h</code>, through two different intermediate files, but neither <code>a.h</code> nor <code>a.cpp</code> depend in any way on <code>off.h</code>.</p>
  
  <p>Before you ask, I made sure that all files were wrapped in multiple definition guards (<code>#ifndef</code>, <code>#define</code>, <code>#endif</code>), and while I did find a file that was missing them, it did not reference <code>off.h</code>.  More importantly, <code>b.h</code> does not include anything that references <code>off.h</code>, only the implementation, <code>b.cpp</code>, makes any reference to <code>off.h</code>. This alone had me puzzled.  </p>
  
  <p>To add to my confusion, I was able to remove the reference to <code>off.h</code> from <code>b.cpp</code> and, as expected, it recompiled successfully.  However, when I added the reference back in, it also compiled successfully, and continued to do so after cleaning out the object files. I am still at a loss for why it was failing to compile, especially considering that the symbols should not have conflicted, I had prevented symbol duplication, and I had gotten rid of any prior/incomplete builds.</p>
  
  <p>Since I was able to successfully compile my program, I doubt I'll be able to reproduce it to test out any suggestions. However, I am curious as to how this can happen, and if I run across this behavior in the future, what, if anything beyond what I've done, might I do to fix it?</p>