title: Call to function in header of other file undefined reference
body: <p>First of all, I'd like to say I'm somewhat inexperienced with c++.</p>
  
  <p>I am working on a project for university using catkin. In it I have 3 files (relevant to this question), <strong>TestCode.cpp</strong>, <strong>RobotInfo.cpp</strong> and <strong>RobotInfo.h</strong>.</p>
  
  <p>And they have the following code inside of them:</p>
  
  <p><code>TestCode.cpp</code></p>
  
  <pre><code>#include "RobotInfo.h"
  
  int main(int argc, char **argv) {
      ....
      Joints::size(); //first time any call goes to Joints    
      ...
  }
  </code></pre>
  
  <p><code>RobotInfo.h</code></p>
  
  <pre><code>class Joints{
  protected:
      static map&lt;string, double&gt; info;
  
  public:
      static int size();
  }
  </code></pre>
  
  <p><code>RobotInfo.cpp</code></p>
  
  <pre><code>#include "RobotInfo.h"
  
  map&lt;string, double &gt; Joints::info = map&lt;string, double&gt;();
  
  int Joints::size() {
      return (int) info.size();
  }
  </code></pre>
  
  <p>Plus they have all been added in CMakeLists.txt.</p>
  
  <p>Now everytime I try to run it I get the following error: <strong>undefined reference to `Joints::size()'</strong> , pointing to the line of the size() call in TestCode.cpp.</p>
  
  <p>If I change the include in TestCode.cpp to #include"RobotInfo.cpp" everything works fine, but to me that kind of looks like a dirty solution.</p>
  
  <p>So what I'd like to know is what could be causing this problem, I've tried solving this for hours but it seems my lack of experience is really hurting me on this one.</p>
  
  <p>Also here's everything the console outputs when I build it:</p>
  
  <pre><code>/home/manuel/clion-2017.1.1/bin/cmake/bin/cmake --build /home/manuel/catkin_ws/src/cmake-build-debug --target testCode -- -j 4
  Scanning dependencies of target testCode
  [ 50%] Building CXX object team1/CMakeFiles/testCode.dir/src/TestCode.cpp.o
  [100%] Linking CXX executable ../devel/lib/team1/testCode
  CMakeFiles/testCode.dir/src/TestCode.cpp.o: In function `main':
  /home/manuel/catkin_ws/src/team1/src/TestCode.cpp:32: undefined reference to `Joints::size()'
  collect2: error: ld returned 1 exit status
  team1/CMakeFiles/testCode.dir/build.make:113: recipe for target 'devel/lib/team1/testCode' failed
  make[3]: *** [devel/lib/team1/testCode] Error 1
  CMakeFiles/Makefile2:784: recipe for target 'team1/CMakeFiles/testCode.dir/all' failed
  make[2]: *** [team1/CMakeFiles/testCode.dir/all] Error 2
  CMakeFiles/Makefile2:796: recipe for target 'team1/CMakeFiles/testCode.dir/rule' failed
  make[1]: *** [team1/CMakeFiles/testCode.dir/rule] Error 2
  Makefile:446: recipe for target 'testCode' failed
  make: *** [testCode] Error 2
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I figured it out, it was a stupid mistake on my part, I made a mistake on my CMakeLists and it wasn't compiling both files together, special thanks to @NathaOliver for pointing that out to me. And sorry for wasting your time on such a simple problem.</p>