title: Undefined reference after using CMAKE to generate a makefile
body: <p>I can generate my CMake project, but I can't build it.</p>
  
  <p>I have a fairly straightforward project structure:</p>
  
  <pre><code>├── bin                                                                                                                                                                                                                                       
  ├── build                                                                                                                                                                                                                                     
  ├── CMakeLists.txt                                                                                                                                                                                                                            
  ├── include                                                                                                                                                                                                                                   
  │   └── project                                                                                                                                                                                                                               
  │       ├── base_socket.h                                                                                                                                                                                                                     
  │       ├── tcp_client.h                                                                                                                                                                                                                      
  │       ├── tcp_server.h                                                                                                                                                                                                                      
  │       ├── udp_client.h                                                                                                                                                                                                                      
  │       └── udp_server.h                                                                                                                                                                                                                      
  ├── LICENSE.txt                                                                                                                                                                                                                               
  ├── README.md                                                                                                                                                                                                                                 
  └── src                                                                                                                                                                                                                                       
      └── project                                                                                                                                                                                                                               
          ├── base_socket.cpp                                                                                                                                                                                                                   
          ├── CMakeLists.txt                                                                                                                                                                                                                    
          ├── main.cpp                                                                                                                                                                                                                          
          ├── tcp_client.cpp                                                                                                                                                                                                                    
          ├── tcp_server.cpp                                                                                                                                                                                                                    
          ├── udp_client.cpp                                                                                                                                                                                                                    
          └── udp_server.cpp 
  </code></pre>
  
  <p>And a fairly straight forward CMakeLists.txt file in the top directory:</p>
  
  <pre><code># Project initialization                                                                                                                                                                                                                      
  cmake_minimum_required(VERSION 2.7.2 FATAL_ERROR)                                                                                                                                                                                             
  
  project("cpp_sockets")                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
  
  # Add include directory                                                                                                                                                                                                                       
  include_directories(include)                                                                                                                                                                                                                  
  
  # Add subdirectories                                                                                                                                                                                                                          
  add_subdirectory(src/project)                                                                                                                                                                                                                 
  </code></pre>
  
  <p>And also a fairly simple one in <code>src/project/CmakeLists.txt</code>:</p>
  
  <pre><code>set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)                                                                                                                                                                                   
  set(HEADER_DIR ${CMAKE_SOURCE_DIR}/include/project)                                                                                                                                                                                           
  set(HEADER_FILES                                                                                                                                                                                                                              
    ${HEADER_DIR}/base_socket.h                                                                                                                                                                                                                 
    ${HEADER_DIR}/tcp_client.h                                                                                                                                                                                                                  
    ${HEADER_DIR}/tcp_server.h                                                                                                                                                                                                                  
    ${HEADER_DIR}/udp_client.h                                                                                                                                                                                                                  
    ${HEADER_DIR}/udp_server.h                                                                                                                                                                                                                  
    )                           
  
  add_executable(cpp_sockets main.cpp ${HEADER_FILES}) 
  </code></pre>
  
  <p>When I <code>cd</code> into <code>/build</code> and type <code>cmake ..</code> it works fine.</p>
  
  <p>However, when I follow that with <code>make</code>, I get many terrible errors about <code>undefined reference</code>.</p>
  
  <pre><code>main.cpp:(.text+0x2c6): undefined reference to `UDPClient::UDPClient(int, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'                                                                            
  main.cpp:(.text+0x2eb): undefined reference to `UDPClient::send_message(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'                                                                              
  main.cpp:(.text+0x359): undefined reference to `UDPServer::UDPServer(int, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'                                                                            
  main.cpp:(.text+0x380): undefined reference to `UDPServer::socket_bind()'                                                                                                                                                                     
  main.cpp:(.text+0x38c): undefined reference to `UDPServer::listen()'                                                                                                                                                                          
  main.cpp:(.text+0x400): undefined reference to `TCPClient::TCPClient(int, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'                                                                            
  main.cpp:(.text+0x40c): undefined reference to `TCPClient::make_connection()'                                                                                                                                                                 
  main.cpp:(.text+0x42b): undefined reference to `TCPClient::send_message(std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'                                                                              
  main.cpp:(.text+0x492): undefined reference to `TCPServer::TCPServer(int, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'                                                                            
  main.cpp:(.text+0x4b9): undefined reference to `TCPServer::socket_bind()'                                                                                                                                                                     
  CMakeFiles/cpp_sockets.dir/main.cpp.o: In function `UDPClient::~UDPClient()':                                                                                                                                                                 
  main.cpp:(.text._ZN9UDPClientD2Ev[_ZN9UDPClientD5Ev]+0x14): undefined reference to `Socket::~Socket()'                                                                                                                                        
  CMakeFiles/cpp_sockets.dir/main.cpp.o: In function `UDPServer::~UDPServer()':                                                                                                                                                                 
  main.cpp:(.text._ZN9UDPServerD2Ev[_ZN9UDPServerD5Ev]+0x14): undefined reference to `Socket::~Socket()'                                                                                                                                        
  CMakeFiles/cpp_sockets.dir/main.cpp.o: In function `TCPClient::~TCPClient()':                                                                                                                                                                 
  main.cpp:(.text._ZN9TCPClientD2Ev[_ZN9TCPClientD5Ev]+0x14): undefined reference to `Socket::~Socket()'                                                                                                                                        
  CMakeFiles/cpp_sockets.dir/main.cpp.o: In function `TCPServer::~TCPServer()':                                                                                                                                                                 
  main.cpp:(.text._ZN9TCPServerD2Ev[_ZN9TCPServerD5Ev]+0x14): undefined reference to `Socket::~Socket()'                                                                                                                                        
  collect2: error: ld returned 1 exit status                                                                                                                                                                                                    
  src/project/CMakeFiles/cpp_sockets.dir/build.make:94: recipe for target '../bin/cpp_sockets' failed                                                                                                                                           
  make[2]: *** [../bin/cpp_sockets] Error 1                                                                                                                                                                                                     
  CMakeFiles/Makefile2:85: recipe for target 'src/project/CMakeFiles/cpp_sockets.dir/all' failed                                                                                                                                                
  make[1]: *** [src/project/CMakeFiles/cpp_sockets.dir/all] Error 2                                                                                                                                                                             
  Makefile:83: recipe for target 'all' failed                                                                                                                                                                                                   
  make: *** [all] Error 2
  </code></pre>
  
  <p><code>main.cpp</code> file looks like:</p>
  
  <pre><code>  #include "project/udp_server.h"                                                                                                                                                                                                            
    #include "project/udp_client.h"                                                                                                                                                                                                            
    #include "project/tcp_client.h"       
  </code></pre>
  
  <p>Why would the linker not be able to find the references like this?</p>