title: Static library having object files with same name (ar)
body: <p>A bit context. Let's say I have source files, which need to end up in a static library. Let's say there are two cpp files <code>a.cpp</code> and <code>a.cpp</code> located in two different subdirectories. Something like this:</p>
  
  <pre><code>foo/a.h
  foo/a.cpp
  bar/a.h
  bar/a.cpp
  </code></pre>
  
  <p>Their content is not clashing and is completely different. The file names are just same.</p>
  
  <p>Now, when compiling I end up with two <code>a.o</code> files of course.</p>
  
  <pre><code>gcc -c foo/a.cpp -o foo/a.o
  gcc -c bar/a.cpp -o bar/a.o
  </code></pre>
  
  <p>If I create a static lib now with </p>
  
  <pre><code>ar rcs libfoobar.a foo/a.o bar/a.o
  </code></pre>
  
  <p>I can see both files inside the static library running <code>nm libfoobar.a</code>. Seems fine.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>The problem I can see is if I run the <code>ar</code> command individually for <code>foo/a.o</code> and <code>bar/a.o</code> putting them in the same static library. Now the latter object file will overwrite the former, so when running <code>nm libfoobar.a</code> I just see the latter object in the library. I'm guessing this is the case due to the same object file name.</p>
  
  <p>When creating a static library with <code>ar</code>, should I always combine all objects in one go or is it also fine to run <code>ar</code> multiple times collecting a part of objects at a time all ending up in the same static library? For this example I can see the former works, but not the latter.</p>
  
  <p>How will things work when one <code>a.cpp</code> changes and the static library needs to change? Will <code>ar</code> find the right <code>a.cpp</code> to change in the library?</p>
  
  <p>This is just a small example, but consider a large project with many files and some have the same name. If you now want to create a single library you could end up with this situation as well.</p>
  
  <p><strong>In general, is this just poor organization of how libraries are composed, how files are named or is there something else to this to make things work?</strong></p>