title: CMake cannot find my library file
body: <p>I want to use CMake to create a simple static library <code>Maths</code>, and then link to that library to create a simple executable <code>Alpha</code>.</p>
  
  <p>Here's my directory structure:</p>
  
  <pre><code>/Maths
      /build
          /
      /CMakeLists.txt
      /maths.cpp
      /maths.h
  /Alpha
      /build
          /
      /CMakeLists.txt
      /main.cpp
  </code></pre>
  
  <p>And here are the contents of those files:</p>
  
  <p><strong>* CMakeLists.txt (for Maths) *</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  project(Maths)
  add_library(maths STATIC maths.cpp)
  </code></pre>
  
  <p><strong>* maths.cpp *</strong></p>
  
  <pre><code>int Double(int x)
  {
      int y = x * 2;
      return y;
  }
  </code></pre>
  
  <p><strong>* maths.h *</strong></p>
  
  <pre><code>int Double(int x);
  </code></pre>
  
  <p><strong>* CMakeLists.txt (for Alpha) *</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  project(Alpha)
  add_executable(alpha main.cpp ../Maths/maths.h)
  target_link_libraries(maths ../Maths/build/libmaths.a)
  </code></pre>
  
  <p><strong>* main.cpp *</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include "maths.h"
  
  using namespace std;
  
  int main()
  {
      int x = 5;
      int y = Triple(x);
      cout &lt;&lt; "The answer = " &lt;&lt; y &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>So, I enter the directory <code>/Maths/build</code>, and run <code>cmake ..</code>. Then, I run <code>make</code>. This creates the library file <code>libmaths.a</code> in the directory <code>/Maths/build</code>.</p>
  
  <p>Then, I enter the directory <code>/Alpha/build</code>, and run <code>cmake ..</code>. Then, I run <code>make</code>. However, this gives me the error message:</p>
  
  <pre><code>/usr/bin/ld: cannot find -lmaths
  </code></pre>
  
  <p>Why can make not find the library file that I just created?</p>
  
  <p>I also tried copyiing <code>libmaths.a</code> and <code>maths.h</code> into the directory <code>/Alpha</code>, and changing Alpha's CMakeLists.txt to:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  project(Alpha)
  add_executable(alpha main.cpp maths.h)
  target_link_libraries(maths libmaths.a)
  </code></pre>
  
  <p>But this gave the same error.</p>