title: C++ - Unresolved external symbol error
body: <p>I've been searching around and have come to a stop with this thing.</p>
  
  <p><strong>I basically get these errors here:</strong></p>
  
  <pre><code>1&gt;Client.obj : error LNK2019: unresolved external symbol "class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __cdecl HTTP_POST_REQUEST(char *,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;)" (?HTTP_POST_REQUEST@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADV12@1@Z) referenced in function "public: virtual void __thiscall Client::Send(void)" (?Send@Client@@UAEXXZ)
  1&gt;G:\Development\C++\Client\Debug\Client.exe : fatal error LNK1120: 1 unresolved externals
  </code></pre>
  
  <p>To my knowledge I think it's that Client.obj is not getting compiled with the program (don't quote me on this)?
  But I have read that it might be some linking problems or something like that. To me it seems that I've done everythign right (but clearly I haven't).</p>
  
  <p><strong>Client.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  #include "HttpUtils.h"
  #include "Client.h"
  
  Client::Client() {
      cout &lt;&lt; "Works!" &lt;&lt; endl;
  }
  
  void Client::Send() {
      string res = HTTP_POST_REQUEST("localhost", "/test.php", "data1=data&amp;data2=data");
      cout &lt;&lt; res &lt;&lt; endl;
  }
  </code></pre>
  
  <p><strong>Client.h</strong></p>
  
  <pre><code>#pragma once
  
  #include &lt;string&gt;
  using namespace std;
  
  #ifndef CLIENT__H
  #define CLIENT__H
  
  class Client {
  
  public:
      Client();
  
      virtual void Send();
  };
  #endif
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  #include "Client.h"
  
  int main(int argc, char *argv[]) {
      Client mainClient;
      Client* client1 = &amp;mainClient;
  
      client1-&gt;Send();
      cin.get();
  }
  </code></pre>
  
  <p>Any and all help is great! Thanks!</p>
  
  <p><strong>EXTRA CODE</strong></p>
  
  <p><strong>HttpUtils.cpp</strong></p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;winsock.h&gt;
  #include &lt;sstream&gt;
  #pragma comment (lib, "wsock32.lib")
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  #include "HttpUtils.h"
  
  void die_with_error(char *errorMessage) {
      cerr &lt;&lt; errorMessage &lt;&lt; endl;
      cin.get();
      exit(1);
  }
  
  void die_with_wserror(char *errorMessage) {
      cerr &lt;&lt; errorMessage &lt;&lt; ": " &lt;&lt; WSAGetLastError() &lt;&lt; endl;
      cin.get();
      exit(1);
  }
  
  string HTTP_POST_REQUEST(char *hostname, string path, string data) {
      string request;
      string response;
      int resp_leng;
  
      char buffer[BUFFERSIZE];
      struct sockaddr_in serveraddr;
      int sock;
  
      WSADATA wsaData;
      hostent *remoteHost;
      int port = 80;
  
      stringstream ss;
      ss &lt;&lt; data.length();
  
      stringstream request2;
      request2 &lt;&lt; "POST " &lt;&lt; path &lt;&lt; " HTTP/1.1" &lt;&lt; endl;
      request2 &lt;&lt; "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)" &lt;&lt; endl;
      request2 &lt;&lt; "Host: " &lt;&lt; hostname &lt;&lt; endl;
      request2 &lt;&lt; "Content-Length: " &lt;&lt; data.length() &lt;&lt; endl;
      request2 &lt;&lt; "Content-Type: application/x-www-form-urlencoded" &lt;&lt; endl;
      request2 &lt;&lt; "Accept-Language: en-uk" &lt;&lt; endl;
      request2 &lt;&lt; endl;
      request2 &lt;&lt; data;
      request = request2.str();
  
      cout &lt;&lt; request &lt;&lt; endl &lt;&lt; "###################################################" &lt;&lt; endl &lt;&lt; endl;
  
      //  Init WinSock.
      if (WSAStartup(MAKEWORD(2, 0), &amp;wsaData) != 0)
          die_with_wserror("WSAStartup() failed");
  
      //  Open socket.
      if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) &lt; 0)
          die_with_wserror("socket() failed");
  
  
      //  Convert hostname into IP
      remoteHost = gethostbyname(hostname);
      char *temp;
      if (remoteHost != NULL) {
          temp = remoteHost-&gt;h_addr_list[0];
      } else {
          temp = NULL;
          return "Error: Invalid hostname passed to HTTP_POST().";
      }
  
  
      //  Connect.
      memset(&amp;serveraddr, 0, sizeof(serveraddr));
      serveraddr.sin_family = AF_INET;
  
      int i = 0;
      if (remoteHost-&gt;h_addrtype == AF_INET)
      {
          while (remoteHost-&gt;h_addr_list[i] != 0) {
              serveraddr.sin_addr.s_addr = *(u_long *)remoteHost-&gt;h_addr_list[i++];
          }
      }
  
      serveraddr.sin_port = htons((unsigned short)port);
      if (connect(sock, (struct sockaddr *) &amp;serveraddr, sizeof(serveraddr)) &lt; 0)
          die_with_wserror("connect() failed");
  
      //  Send request.
      if (send(sock, request.c_str(), request.length(), 0) != request.length())
          die_with_wserror("send() sent a different number of bytes than expected");
  
      //  Get response.
      response = "";
      resp_leng = BUFFERSIZE;
      while (resp_leng == BUFFERSIZE)
      {
          resp_leng = recv(sock, (char*)&amp;buffer, BUFFERSIZE, 0);
          if (resp_leng&gt;0)
              response += string(buffer).substr(0, resp_leng);
          //note: download lag is not handled in this code
      }
  
      //  Disconnect
      closesocket(sock);
  
      //  Cleanup
      WSACleanup();
  
      //response.erase(0, 184);
      return  response;
  }
  </code></pre>
  
  <p><strong>HttpUtils.h</strong></p>
  
  <pre><code>#pragma once
  
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  #ifndef HTTP_UTILS__H
  #define HTTP_UTILS__H
  #define BUFFERSIZE 1024
  void die_with_error(char *errorMessage);
  void die_with_wserror(char *errorMessage);
  
  string HTTP_POST_REQUEST(char *hostname, string path, string data);
  #endif
  </code></pre>