title: CMake - Undefined Reference
body: <p>I am trying to include gtest to my project. </p>
  
  <p>The problem is that I get a undefined reference error in the GTest.</p>
  
  <p>I am trying to test the Node class in Gtest. Inside the constructor of the Node I am using the Class Logger. Although I have added the library logger to the gtest-target I still the undefined reference error regarding to the Logger....</p>
  
  <p>My guess CMake does no look for nested classes that are used inside Node.
  only Node itself.</p>
  
  <p><strong>Temperoy fix</strong>
  If I use the Logger in the gtest-node.cpp it works
  gtest.cpp</p>
  
  <pre><code>/* Pseudo Code */
  TEST Node
  { 
       Logger::log("Temp Fix")
       Node * n = Node(0,0,0)
  }
  </code></pre>
  
  <p>This way the the Logger is directly used in the gtest this way the logger-library will be add to the target by cmake.</p>
  
  <p>My Setup (pseudo-code because my project is way bigger than this) 
  (<a href="https://github.com/ronsalm/LearningLunch" rel="nofollow noreferrer">https://github.com/ronsalm/LearningLunch</a>)</p>
  
  <pre><code>├── CMakeLists.txt
  ├── main.cpp
  ├── logger
  │   ├── CMakeLists.txt
  │   ├── logger.cpp
  │   └── logger.h
  ├── Node
  │   ├── CMakeLists.txt
  │   ├── node.cpp
  │   └── node.h
  └── Gtest
      ├── CMakeLists.txt
      ├── gtest-node.cpp
      └── node.h
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>/* Pseudo Code */
  int main()
  { 
       Node * n = Node(0,0,0)
  }
  </code></pre>
  
  <p>logger.h</p>
  
  <pre><code>/* Pseudo Code */
  class Logger
  { 
       log(string)
  }
  </code></pre>
  
  <p>logger.cpp</p>
  
  <pre><code>/* Pseudo Code */
  Logger::log(string s)
  {
  //write to string to file
  }
  </code></pre>
  
  <p>node.h</p>
  
  <pre><code>/* Pseudo Code */
  class Node
  { 
       Node(int,int,int)
  }
  </code></pre>
  
  <p>node.cpp</p>
  
  <pre><code>/* Pseudo Code */
  Node::node(int x, int y , int z)
  {
       Logger::log("Create Node")
  }
  </code></pre>
  
  <p>gtest.cpp</p>
  
  <pre><code>/* Pseudo Code */
  TEST Node
  { 
       Node * n = Node(0,0,0)
  }
  </code></pre>
  
  <p>CMakeLists.txt (Root)</p>
  
  <pre><code>project(applic)
  include_directories(
        "${CMAKE_SOURE_DIR/node"
        "${CMAKE_SOURE_DIR/logger")
  
  add_library(node node.cpp)
  add_executable(applic main.cpp)
  target_link_libraries(applic logger node)
  </code></pre>
  
  <p>CMakeLists.txt (Logger)</p>
  
  <pre><code>add_library(logger logger.cpp)
  </code></pre>
  
  <p>CMakeLists.txt (Node)</p>
  
  <pre><code>add_library(node node.cpp)
  </code></pre>
  
  <p>CMakeLists.txt (Gtest)</p>
  
  <pre><code>add_executable(gtest-node gtest-node.cpp)
  set_target_properties(gtest-node PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
  target_link_libraries(gtest-logger gtest phtread logger node)
  add_test(NAME node COMMAND $&lt;TARGET_FILE:gtest-node&gt;
  
  enable_testing()
  </code></pre>
  
  <p>The original error:</p>
  
  <pre><code>../../../../lib/libdatabase.a(sql.cpp.o): In function `SQL::Open()':
  /home/rsalm/test/src/database/sql/sql.cpp:19: undefined reference to `Logger::TagDebug'
  /home/rsalm/test/src/database/sql/sql.cpp:19: undefined reference to `Logger::instance(std::string const&amp;)                                               '
  ../../../../lib/libdatabase.a(sql.cpp.o): In function `SQL::Close()':
  /home/rsalm/test/src/database/sql/sql.cpp:27: undefined reference to `Logger::TagDebug'
  /home/rsalm/test/src/database/sql/sql.cpp:27: undefined reference to `Logger::instance(std::string const&amp;)                                               '
  ../../../../lib/libdatabase.a(sql.cpp.o): In function `Logger&amp; operator&lt;&lt; &lt;char [25]&gt;(Logger&amp;, char const (&amp;) [25])                                               ':
  /home/rsalm/test/inc/logger.h:33: undefined reference to `Logger::pInstance'
  ../../../../lib/libdatabase.a(sql.cpp.o): In function `Logger&amp; operator&lt;&lt; &lt;char [21]&gt;(Logger&amp;, char const (&amp;) [21])                                               ':
  /home/rsalm/test/inc/logger.h:33: undefined reference to `Logger::pInstance'
  ../../../../lib/libdatabase.a(sql.cpp.o): In function `Logger&amp; operator&lt;&lt; &lt;char [26]&gt;(Logger&amp;, char const (&amp;) [26])                                               ':
  /home/rsalm/test/inc/logger.h:33: undefined reference to `Logger::pInstance'
  ../../../../lib/libdatabase.a(sql.cpp.o): In function `Logger&amp; operator&lt;&lt; &lt;char [24]&gt;(Logger&amp;, char const (&amp;) [24])                                               ':
  /home/rsalm/test/inc/logger.h:33: undefined reference to `Logger::pInstance'
  collect2: error: ld returned 1 exit status
  src/layout/gtest/CMakeFiles/gtest-layout-factory.dir/build.make:98: recipe for target '../bin/gtest-layout-factory'                                                failed
  make[2]: *** [../bin/gtest-layout-factory] Error 1
  CMakeFiles/Makefile2:1824: recipe for target 'src/layout/gtest/CMakeFiles/gtest-layout-factory.dir/all' failed
  </code></pre>