title: Duplicate Symbols Error - Am I doing my includes right?
body: <p>I am working on a project with several modules and I'm getting a lot of duplicate symbols errors. I've tried to create a stripped-down version of my project to diagnose the error.</p>
  <p>I have the code and dependency structure below. Every .hpp and .tpp file has header guards, but I'm getting duplicate symbols errors from MyClass.cpp and main.cpp.</p>
  <p>Is my inclusion structure ok, and any ideas how I can go about fixing the error?</p>
  <p><a href="https://i.stack.imgur.com/h0was.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h0was.png" alt="inclusion structure" /></a></p>
  <p>CMakeLists.txt</p>
  <pre><code>cmake_minimum_required(VERSION 3.18.0)
  project(&quot;duplicate symbols&quot; LANGUAGES CXX)
  set(CMAKE_CXX_STANDARD 20)
  add_executable(main main.cpp MyClass.cpp)
  </code></pre>
  <p>Base.hpp</p>
  <pre><code>#pragma once
  
  template &lt;typename T&gt;
  struct Base { void hello_base() const; };
  
  #include &quot;Base.tpp&quot;
  #include &quot;BaseSpec.hpp&quot;
  </code></pre>
  <p>Base.tpp</p>
  <pre><code>#pragma once
  
  #include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  void Base&lt;T&gt;::hello_base() const { std::cout &lt;&lt; &quot;hello base&quot; &lt;&lt; std::endl; }
  </code></pre>
  <p>BaseSpec.hpp</p>
  <pre><code>#pragma once
  
  template &lt;&gt;
  struct Base&lt;int&gt; { void hello_base() const; };
  
  #include &quot;BaseSpec.tpp&quot;
  </code></pre>
  <p>BaseSpec.tpp</p>
  <pre><code>#pragma once
  
  #include &lt;iostream&gt;
  
  void Base&lt;int&gt;::hello_base() const
  {
      std::cout &lt;&lt; &quot;Hello base int&quot; &lt;&lt; std::endl;
  }
  </code></pre>
  <p>MyClass.hpp</p>
  <pre><code>#pragma once
  
  #include &quot;Base.hpp&quot;
  
  struct MyClass
  {
      void hello_myclass() const;
  };
  </code></pre>
  <p>MyClass.cpp</p>
  <pre><code>#include &quot;MyClass.hpp&quot;
  
  void MyClass::hello_myclass() const
  {
      std::cout &lt;&lt; &quot;hello myclass&quot; &lt;&lt; std::endl;
  }
  </code></pre>
  <p>main.cpp</p>
  <pre><code>#include &quot;MyClass.hpp&quot;
  
  int main() {}
  </code></pre>
  <p>The error message is:</p>
  <pre><code>duplicate symbol 'Base&lt;int&gt;::hello_base() const' in:
      CMakeFiles/main.dir/main.cpp.o
      CMakeFiles/main.dir/myclass.cpp.o
  </code></pre>