title: c++ Generating static library and then using it with Clion/Cmake
body: <p>I've been searching the web and trying for a few hours to get this to work. However I'm running into a brick wall. </p>
  
  <p>I have a small collection of helper classes that can be very useful across projects. I want to put these into a static library so I can include it on any project I work on. </p>
  
  <p>I have successfully created a file libMyTestLibrary.a and put it in my /usr/lib/ folder. The problem I am running into now is using that static library in a different Clion project (version 1.2 running on linux Mint 17.2)</p>
  
  <p>I will be using some very simple stand in classes to demonstrate the process. </p>
  
  <p>The myTestClass.h file:</p>
  
  <pre><code>//assume header guard, etc. 
  class myTestClass
  {
  public:
      int add(const int&amp; lhs, const int&amp; rhs) const;
  };
  </code></pre>
  
  <p>The myTestClass.cpp file:</p>
  
  <pre><code>#include "myTestClass.h"
  
  int myTestClass::add(const int &amp;lhs, const int &amp;rhs) const
  {
      return lhs + rhs;
  }
  </code></pre>
  
  <p>To generate the .a file I am following the instructions in <a href="http://www.hep.wisc.edu/~pinghc/generate_your_own_library.htm" rel="nofollow">this tutorial</a>.</p>
  
  <p>I run the following terminal commands:</p>
  
  <pre><code>beaky@BeakyDesktop ~/Documents/Programming/testProject $ g++ -c myTestClass.cpp
  </code></pre>
  
  <p>This successfully generates a myTestClass.o file. Then I run: </p>
  
  <pre><code>beaky@BeakyDesktop ~/Documents/Programming/testProject $ ar cr libMyTestLibrary.a myTestClass.o
  </code></pre>
  
  <p>My .a file has been created. I then move it into /usr/lib/ using the command:</p>
  
  <pre><code>beaky@BeakyDesktop ~/Documents/Programming/testProject $ sudo mv libMyTestLibrary.a /usr/lib/
  </code></pre>
  
  <p>The .a library now lives in my /usr/lib folder. </p>
  
  <p>I create a new Clion project called testProject2 where I want to use my newly created library. Here is where I am running into trouble!</p>
  
  <p>In my CMakeLists.txt file I include the line:</p>
  
  <pre><code>TARGET_LINK_LIBRARIES(testProject2 /usr/lib/libMyTestLibrary.a)
  </code></pre>
  
  <p>I though this would fully include the library in my project that way in main.cpp (or anywhere else) and that I could do something like:</p>
  
  <pre><code>#include "myTestClass.h"
  
  int main()
  {
      int result = add(1, 3);
      return 0;
  }
  </code></pre>
  
  <p>However this results in errors! myTestClass.h could not be found. Am I including this static library correctly? Am I right to assume that I should be using Cmake to include my custom library? If so what is the correct way to include my custom .a file my project using clion and cmake? </p>