title: error linking GMP library
body: <p>I have the following CMakeList.txt</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
  find_package(GMP REQUIRED)
  add_executable(Turrial main.cpp)
  </code></pre>
  
  <p>with the following simple source file main.cpp </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;gmp.h&gt;
  #include &lt;cstdio&gt;
  
  using namespace std;
  int main(){ 
      mpz_t a,b;
      mpz_init_set_str(a,"45",10);
      mpz_init_set_str(b,"12",10);
      mpz_add(a,a,b);
      cout &lt;&lt;mpz_get_str(NULL,10,a)&lt;&lt;endl;    
      }
  </code></pre>
  
  <p>I have included a FindGMP.cmake file that i found online :</p>
  
  <pre><code>set(GMP_PREFIX "" CACHE PATH "path ")
  
  
  find_path(GMP_INCLUDE_DIR gmp.h gmpxx.h 
      PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include )
  
  find_library(GMP_LIBRARY NAMES gmp libgmp 
      PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib)
  
  
  if(GMP_INCLUDE_DIR AND GMP_LIBRARY)
      get_filename_component(GMP_LIBRARY_DIR ${GMP_LIBRARY} PATH)
      set(GMP_FOUND TRUE)
  endif()
  
  if(GMP_FOUND)
     if(NOT GMP_FIND_QUIETLY)
        MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
     endif()
  elseif(GMP_FOUND)
     if(GMP_FIND_REQUIRED)
        message(FATAL_ERROR "Could not find GMP")
     endif()
  endif(
  </code></pre>
  
  <p>when I run cmake I have the following output:</p>
  
  <pre><code>moyle@localhost:~/Desktop/gmptri$ cmake .
  -- Found GMP: /usr/local/lib/libgmp.so
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /home/moyle/Desktop/gmptri
  </code></pre>
  
  <p>Then I run make and i get the following errors :</p>
  
  <pre><code>  (precise)moyle@localhost:~/Desktop/gmptri$ make VERBOSE=1
  /usr/bin/cmake -H/home/moyle/Desktop/gmptri -B/home/moyle/Desktop/gmptri --check-build-system CMakeFiles/Makefile.cmake 0
  /usr/bin/cmake -E cmake_progress_start /home/moyle/Desktop/gmptri/CMakeFiles /home/moyle/Desktop/gmptri/CMakeFiles/progress.marks
  make -f CMakeFiles/Makefile2 all
  make[1]: Entering directory `/home/moyle/Desktop/gmptri'
  make -f CMakeFiles/Turrial.dir/build.make CMakeFiles/Turrial.dir/depend
  make[2]: Entering directory `/home/moyle/Desktop/gmptri'
  cd /home/moyle/Desktop/gmptri &amp;&amp; /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/moyle/Desktop/gmptri /home/moyle/Desktop/gmptri /home/moyle/Desktop/gmptri /home/moyle/Desktop/gmptri /home/moyle/Desktop/gmptri/CMakeFiles/Turrial.dir/DependInfo.cmake --color=
  make[2]: Leaving directory `/home/moyle/Desktop/gmptri'
  make -f CMakeFiles/Turrial.dir/build.make CMakeFiles/Turrial.dir/build
  make[2]: Entering directory `/home/moyle/Desktop/gmptri'
  Linking CXX executable Turrial
  /usr/bin/cmake -E cmake_link_script CMakeFiles/Turrial.dir/link.txt --verbose=1
  /usr/bin/c++       CMakeFiles/Turrial.dir/main.cpp.o  -o Turrial -rdynamic 
  CMakeFiles/Turrial.dir/main.cpp.o: In function `main':
  main.cpp:(.text+0x1a): undefined reference to `__gmpz_init_set_str'
  main.cpp:(.text+0x30): undefined reference to `__gmpz_init_set_str'
  main.cpp:(.text+0x47): undefined reference to `__gmpz_add'
  collect2: ld returned 1 exit status
  make[2]: *** [Turrial] Error 1
  make[2]: Leaving directory `/home/moyle/Desktop/gmptri'
  make[1]: *** [CMakeFiles/Turrial.dir/all] Error 2
  make[1]: Leaving directory `/home/moyle/Desktop/gmptri'
  make: *** [all] Error 2
  </code></pre>
  
  <p>can anyone help me?</p>