title: Why doesn't this create multiple defined symbols in this static library?
body: <p>In a static library project, I have a header file with declared but not implemented functions.</p>
  
  <p>I have a .cpp file that implements these functions.</p>
  
  <p>Then, to better understand linker errors, I copied the cpp file so I have an exact duplicate of it that also gets compiled. So, both files have double implementations for every symbol in the header.</p>
  
  <p>It compiles, and when used in another project, it links.</p>
  
  <p>Here a minimum example for static library:</p>
  
  <p>api.hpp:</p>
  
  <pre><code>void printWhatever();
  </code></pre>
  
  <p>errortest.cpp and duplicate.cpp are identical:</p>
  
  <pre><code>#include "api.hpp"
  #include &lt;iostream&gt;
  void printWhatever(){
    std::cout &lt;&lt; "hi " &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>I compile this as a static library with these 2 source files. I see the compiler produce reports for both files.</p>
  
  <p>Now I use this compiled library in an executable, a different project:
  main.cpp:</p>
  
  <pre><code>#include &lt;api.hpp&gt;
  int main(int argc, const char * argv[]) {
    printWhatever();
  
    return 0;
  }
  </code></pre>
  
  <p>It runs and prints "hi".</p>
  
  <p>Why is there not a multiple definition for the function?</p>