title: GTest linking error: undefined reference to 'foo::function'
body: <p>I want to use GTest and got the example to work. Now I want to test my own code, but I get a linking problem.</p>
  
  <p>I've search on stackoverflow, and found a similar problem but the answers didn't help me to fix my problem.</p>
  
  <p>My files are:</p>
  
  <p><strong>CMakeLists.txt</strong></p>
  
  <pre><code>cmake_minimum_required(VERSION 2.6)
  
  SET(CMAKE_CXX_FLAGS "-std=gnu++11")
  
  # Locate GTest
  find_package(GTest REQUIRED)
  include_directories(${GTEST_INCLUDE_DIRS})
  file(GLOB files
      Datahandler.h 
      Datahandler.cpp 
      )
  
  # Link runTests with what we want to test and the GTest and pthread library
  add_executable(runTests tests.cpp ${files} )
  target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
  </code></pre>
  
  <p><strong>tests.cpp</strong></p>
  
  <pre><code>#include "DataHandler.h"
  #include &lt;gtest/gtest.h&gt;
  
  TEST(checkFilled, All){
      DataHandler handler("loc", "prot", 1);
      handler.filledElement[1] = 1;
      ASSERT_EQ(1, handler.checkFilled(1));
      ASSERT_EQ(0, handler.checkFilled(2));
      ASSERT_EQ(1, handler.checkFilled(8));
      ASSERT_EQ(0, handler.checkFilled(9));
  }
  
  int main(int argc, char **argv) {
      testing::InitGoogleTest(&amp;argc, argv);
      return RUN_ALL_TESTS();
  }
  </code></pre>
  
  <p>The errors I get are:</p>
  
  <pre><code>CMakeFiles/runTests.dir/tests.cpp.o: In function `checkFilled_All_Test::TestBody()':
  tests.cpp:(.text+0x121): undefined reference to `DataHandler::DataHandler(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, unsigned char)'
  tests.cpp:(.text+0x172): undefined reference to `DataHandler::checkFilled(unsigned char)'
  tests.cpp:(.text+0x271): undefined reference to `DataHandler::checkFilled(unsigned char)'
  tests.cpp:(.text+0x382): undefined reference to `DataHandler::checkFilled(unsigned char)'
  tests.cpp:(.text+0x48d): undefined reference to `DataHandler::checkFilled(unsigned char)'
  collect2: error: ld returned 1 exit status
  CMakeFiles/runTests.dir/build.make:95: recipe for target 'runTests' failed
  make[2]: *** [runTests] Error 1
  CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
  make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
  Makefile:83: recipe for target 'all' failed
  make: *** [all] Error 2
  </code></pre>
  
  <p>I'm almost certain it has something to do with include or link problem, but I cant find the right syntax.</p>