title: LNK2019: Unresolved external symbol
body: <p>I've seen plenty of other questions like this but I just couldn't figure this problem out with the help of them. I've understood that it's a linking problem but from what I can see, I've got the linking straightened out. </p>
  
  <p>I'm writing a chat server/client (with the help of <a href="http://johnnie.jerrata.com/winsocktutorial/" rel="nofollow" title="this">this article</a>).</p>
  
  <p>I've defined a class to hold the server functions and have a header-file that handles all the includes. </p>
  
  <p>This is the header file:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;winsock.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  #include &lt;strsafe.h&gt;
  #include "resource1.h"
  
  
  class ChatServer
  {
      public: int InitServer(HINSTANCE hInst);
  
      public: void ReportError(int errorCode, const char *whichFunc);
  };
  </code></pre>
  
  <p>This is the actual server "class":</p>
  
  <pre><code>#include "server.h"
  #define NETWORK_ERROR -1
  #define NETWORK_OK     0
  //Keeps stuff for the server    
  int ChatServer::InitServer(HINSTANCE hInst)
      {
          WORD sockVersion;
          WSADATA wsaData;
          int nret;
  
          sockVersion = MAKEWORD(1,1); //Version 1.1
  
          //Init winsock
          WSAStartup(sockVersion, &amp;wsaData);
  
          //Create listening socket
          SOCKET listeningSocket;
  
          //AFINET - Go over TCP
          //SOCK_STREAM - Stream oriented socket
          //IPPROTO_TCP - Use tcp rather than udp
          listeningSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP);
  
          if(listeningSocket == INVALID_SOCKET)
          {
              nret = WSAGetLastError(); //Get error detail
              ReportError(nret, "socket()");
  
              WSACleanup();
  
              return NETWORK_ERROR;
          }
  
          SOCKADDR_IN serverInfo;
  
          serverInfo.sin_family = AF_INET;
          serverInfo.sin_addr.s_addr = INADDR_ANY;
          serverInfo.sin_port = htons(1337); 
  
          //Bind the socket to local server address.
          nret = bind(listeningSocket, (LPSOCKADDR)&amp;serverInfo, sizeof(struct sockaddr));
  
          if(nret == SOCKET_ERROR)
          {
              nret = WSAGetLastError();
              ReportError(nret, "bind()");
              WSACleanup();
              return NETWORK_ERROR;
          }
  
          //Make socket listen
          nret = listen(listeningSocket, 10); //Up to 10 connections at the same time.
  
          if(nret = SOCKET_ERROR)
          {
              nret = WSAGetLastError();
              ReportError(nret, "listen()");
              WSACleanup();
              return NETWORK_ERROR;
          }
  
          //Wait for client
          SOCKET theClient;
          theClient = accept(listeningSocket, NULL, NULL);
  
          if(theClient == INVALID_SOCKET)
          {
              nret = WSAGetLastError();
              ReportError(nret, "accept()");
              WSACleanup();
              return NETWORK_ERROR;
          }
  
          //Send and receive from the client, and finally,
          closesocket(theClient);
          closesocket(listeningSocket);
  
          //shutdown
          WSACleanup();
          return NETWORK_OK;
      }
  
  
  
  void ChatServer::ReportError(int errorCode, const char *whichFunc)
  
      {
  
         char errorMsg[92];                   // Declare a buffer to hold
                                              // the generated error message
         ZeroMemory(errorMsg, 92);            // Automatically NULL-terminate the string
         // The following line copies the phrase, whichFunc string, and integer errorCode into the buffer
         sprintf(errorMsg, "Call to %s returned error %d!", (char *)whichFunc, errorCode);
  
  
  
         MessageBox(NULL, errorMsg, "socketIndication", MB_OK);
  
      }
  </code></pre>
  
  <p>And lastly, the main.cpp file with the entry-method for the program calls "ChatServer::InitServer(g_hInst)". It's pretty big so I omitted it but if it's needed I'll post it aswell.</p>
  
  <p>The error messages I'm getting are like the one below but they all state problems with the api-functions related to winsockets API: </p>
  
  <pre><code>Error   3   error LNK2019: unresolved external symbol _closesocket@4 referenced in function "public: int __thiscall ChatServer::InitServer(struct HINSTANCE__ *)" (?InitServer@ChatServer@@QAEHPAUHINSTANCE__@@@Z)  
  </code></pre>
  
  <p>As I stated before, I believe this problem has something to do with the compiler misunderstanding what to do with functions like "closesocket" that should be linked to winsock.h.</p>
  
  <p>Thanks for any advice at all and thanks for reading all of this gibberish :)</p>