title: C++ Linking error : the compiler can not find the definition of the function
body: <p>I have a file Cache.cpp that has a corresponding header file Cache.h and another NetFunctions.cpp that has a corresponding header file NetFunction.h.</p>
  
  <p>I have a makefile that looks like this</p>
  
  <pre><code>all: net cache
      g++ main.cpp ../obj/NetFunctions.o ../obj/Cache.o -o ../bin/main
  net: NetFunctions.cpp
      g++ -c NetFunctions.cpp -o ../obj/NetFunctions.o
  cache: Cache.cpp net
      g++ -c Cache.cpp ../obj/NetFunctions.o -o ../obj/Cache.o
  </code></pre>
  
  <p>Now NetFunctions.cpp has a function getNFHTML(string) defined there, which is used in Cache.cpp. I have checked the header files and they look fine with all the functions, declared there and header files properly included.</p>
  
  <p>However, when I make, I get the following linker error</p>
  
  <pre><code>../obj/Cache.o: In function `Cache::getHTML(std::basic_string&lt;char,  std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)':
  Cache.cpp:(.text+0x19ee): undefined reference to `getNFHTML(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)'
  collect2: ld returned 1 exit status
  make: *** [test] Error 1***
  </code></pre>
  
  <p>Can someone help me with this? What is the problem?</p>
  
  <p>I have also referred to this post <a href="https://stackoverflow.com/questions/5481409/c-linking-error">C++ Linking error</a>, but it was of no help to me.</p>
  
  <h2>Edit</h2>
  
  <p>Here is the code:
  NetFunctions.h</p>
  
  <pre><code>#ifndef NET
  #define NET 1
  
  #include "commons.h"
  
  bool serv_bind(struct addrinfo **servinfo, struct addrinfo **p, int *sockfd, int *yes);
  void* get_in_addr(struct sockaddr *sa);
  string getNFHTML(string website);  
  string saveHeaders(string);
  //bool getNFHTML(string request, string last_modified, string *response);
  extern bool useCache;
  
  #endif
  </code></pre>
  
  <p>NetFunctions.cpp</p>
  
  <pre><code>    #include "NetFunctions.h"
      string getNFHTML(string request)
      {
      // a lot of code
      }
  </code></pre>
  
  <p>Cache.cpp</p>
  
  <pre><code>#include "NetFunctions.h"
  #include "Cache.h"
  string Cache::getHTML(string request)
  {
  //some code
      string response = getNFHTML(request);
  //some code
  }
  </code></pre>
  
  <p>I have stripped the files as they contained several hundred lines</p>