title: Error when linking gtest project
body: <p>recently I start study unit testing , and I want test my program with gtest. I install all with this order :</p>
  
  <pre><code>$ git clone https://github.com/google/googletest 
  $ cd googletest 
  $ cmake -DBUILD_SHARED_LIBS=ON . 
  $ make 
  $ cd googlemock 
  $ sudo cp ./libgmock_main.so ./gtest/libgtest.so gtest/libgtest_main.so ./libgmock.so /usr/lib/ 
  $ sudo ldconfig
  </code></pre>
  
  <p>and now write code :</p>
  
  <pre><code>#include "gtest/gtest.h"
  
  class Add
  {
    private:
       int element;
    public:
       Add():element(0){}
       ~Add(){}
       void setElement(int e){ element = e; }
       int getElement() { return element; }
       int adder(int e) { return element += e; }
  };
  
  class AddTest : public ::testing::Test
  {
    protected:
         int abc(int a){
              return a;
          }
  
       virtual void SetUp(){
            add1.setElement(1);
            add2.setElement(20);
       }
       virtual void TearDown(){}
  
  Add add1;
  Add add2;
  };
  
  TEST_F(AddTest, getTest)
  {
     EXPECT_EQ(1, add1.getElement());
     EXPECT_EQ(20, add2.getElement());
  }
  
  int main(int argc, char **argv)
  {
     ::testing::InitGoogleTest(&amp;argc, argv);
     return RUN_ALL_TESTS();
  }
  </code></pre>
  
  <p>end when I run test i get this error :</p>
  
  <p>CMakeFiles/mock2.dir/main.cpp.o: In function <code>AddTest_getTest_Test::TestBody()':
  /home/artem/CLionProjects/mock2/main.cpp:33: undefined reference to</code>testing::Message::Message()'
  /home/artem/CLionProjects/mock2/main.cpp:33: undefined reference to <code>testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
  /home/artem/CLionProjects/mock2/main.cpp:33: undefined reference to</code>testing::internal::AssertHelper::operator=(testing::Message const&amp;) const'
  /home/artem/CLionProjects/mock2/main.cpp:33: undefined reference to <code>testing::internal::AssertHelper::~AssertHelper()'
  /home/artem/CLionProjects/mock2/main.cpp:34: undefined reference to</code>testing::Message::Message()'
  /home/artem/CLionProjects/mock2/main.cpp:34: undefined reference to <code>testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
  /home/artem/CLionProjects/mock2/main.cpp:34: undefined reference to</code>testing::internal::AssertHelper::operator=(testing::Message const&amp;) const'
  /home/artem/CLionProjects/mock2/main.cpp:34: undefined reference to <code>testing::internal::AssertHelper::~AssertHelper()'
  /home/artem/CLionProjects/mock2/main.cpp:33: undefined reference to</code>testing::internal::AssertHelper::~AssertHelper()'
  /home/artem/CLionProjects/mock2/main.cpp:34: undefined reference to <code>testing::internal::AssertHelper::~AssertHelper()'
  CMakeFiles/mock2.dir/main.cpp.o: In function</code>main':
  /home/artem/CLionProjects/mock2/main.cpp:39: undefined reference to <code>testing::InitGoogleTest(int*, char**)'
  CMakeFiles/mock2.dir/main.cpp.o: In function</code>__static_initialization_and_destruction_0(int, int)':
  /home/artem/CLionProjects/mock2/main.cpp:31: undefined reference to <code>testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
  CMakeFiles/mock2.dir/main.cpp.o: In function</code>RUN_ALL_TESTS()':
  /usr/local/include/gtest/gtest.h:2235: undefined reference to <code>testing::UnitTest::GetInstance()'
  /usr/local/include/gtest/gtest.h:2235: undefined reference to</code>testing::UnitTest::Run()'
  CMakeFiles/mock2.dir/main.cpp.o: In function <code>AddTest::AddTest()':
  /home/artem/CLionProjects/mock2/main.cpp:15: undefined reference to</code>testing::Test::Test()'
  CMakeFiles/mock2.dir/main.cpp.o: In function <code>AddTest::~AddTest()':
  /home/artem/CLionProjects/mock2/main.cpp:15: undefined reference to</code>testing::Test::~Test()'
  CMakeFiles/mock2.dir/main.cpp.o: In function <code>testing::internal::scoped_ptr&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;::reset(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;*)':
  /usr/local/include/gtest/internal/gtest-port.h:1172: undefined reference to</code>testing::internal::IsTrue(bool)'
  CMakeFiles/mock2.dir/main.cpp.o: In function <code>testing::internal::scoped_ptr&lt;std::__cxx11::basic_stringstream&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt;::reset(std::__cxx11::basic_stringstream&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;*)':
  /usr/local/include/gtest/internal/gtest-port.h:1172: undefined reference to</code>testing::internal::IsTrue(bool)'
  CMakeFiles/mock2.dir/main.cpp.o: In function <code>testing::AssertionResult testing::internal::CmpHelperEQ&lt;int, int&gt;(char const*, char const*, int const&amp;, int const&amp;)':
  /usr/local/include/gtest/gtest.h:1394: undefined reference to</code>testing::AssertionSuccess()'
  CMakeFiles/mock2.dir/main.cpp.o: In function <code>testing::AssertionResult testing::internal::CmpHelperEQFailure&lt;int, int&gt;(char const*, char const*, int const&amp;, int const&amp;)':
  /usr/local/include/gtest/gtest.h:1384: undefined reference to</code>testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string, std::allocator > const&amp;, std::__cxx11::basic_string, std::allocator > const&amp;, bool)'
  CMakeFiles/mock2.dir/main.cpp.o:(.rodata._ZTI7AddTest[_ZTI7AddTest]+0x10): undefined reference to `typeinfo for testing::Test'
  collect2: error: ld returned 1 exit status
  CMakeFiles/mock2.dir/build.make:94: recipe for target 'mock2' failed
  make[3]: <strong>* [mock2] Error 1
  CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mock2.dir/all' failed
  make[2]: <em></strong> [CMakeFiles/mock2.dir/all] Error 2
  CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/mock2.dir/rule' failed
  make[1]: <strong></em> [CMakeFiles/mock2.dir/rule] Error 2
  Makefile:118: recipe for target 'mock2' failed
  make: *</strong> [mock2] Error 2</p>
  
  <p>but when use command </p>
  
  <pre><code>g++ main.cpp -o test -lgtest -lpthread
  </code></pre>
  
  <p>everytheng is good. How can I fix it and run it not in command line ?</p>