title: Unresolved external symbol LNK2019
body: <p>First of all, I know this question is all over this site but I have looked at almost all of them and can't seem to find out what is wrong. This is in VS 2012. Thanks.</p>
  
  <pre><code>//Socket.h
  #pragma once
  
  #include &lt;iostream&gt;
  #include &lt;WinSock2.h&gt;
  
  using namespace std;
  
  const int STRLEN = 256;
  
  class Socket
  {
      protected:
          WSADATA wsaData;
          SOCKET mySocket;
          SOCKET myBackup;
          SOCKET acceptSocket;
          sockaddr_in myAddress;
      public:
          Socket();
          ~Socket();
          bool SendData( char* );
          bool RecvData( char*, int );
          void CloseConnection();
          void GetAndSendMessage();
  };
  
  class ServerSocket : public Socket
  {
      public:
          void Listen();
          void Bind( int port );
          void StartHosting( int port );
  };
  
  class ClientSocket : public Socket
  {
      public:
          void ConnectToServer( const char *ipAddress, int port );
  };
  </code></pre>
  
  <p>Here's Socket.cpp</p>
  
  <pre><code>//Socket.cpp
  
  
  #include "stdafx.h"
  #include "Socket.h"
  
  
  Socket::Socket()
  {
      if( WSAStartup( MAKEWORD(2, 2), &amp;wsaData ) != NO_ERROR )
      {
          cerr&lt;&lt;"Socket Initialization: Error with WSAStartup\n";
          system("pause");
          WSACleanup();
          exit(10);
      }
  
      //Create a socket
      mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
  
      if ( mySocket == INVALID_SOCKET )
      {
          cerr&lt;&lt;"Socket Initialization: Error creating socket"&lt;&lt;endl;
          system("pause");
          WSACleanup();
          exit(11);
      }
  
      myBackup = mySocket;
  }
  
  Socket::~Socket()
  {
      WSACleanup();
  }
  
  bool Socket::SendData( char *buffer )
  {
      send( mySocket, buffer, strlen( buffer ), 0 );
      return true;
  }
  
  bool Socket::RecvData( char *buffer, int size )
  {
      int i = recv( mySocket, buffer, size, 0 );
      buffer[i] = '\0';
      return true;
  }
  
  void Socket::CloseConnection()
  {
      //cout&lt;&lt;"CLOSE CONNECTION"&lt;&lt;endl;
      closesocket( mySocket );
      mySocket = myBackup;
  }
  
  void Socket::GetAndSendMessage()
  {
      char message[STRLEN];
      cin.ignore();//without this, it gets the return char from the last cin and ignores the following one!
      cout&lt;&lt;"Send &gt; ";
      cin.get( message, STRLEN );
      SendData( message );
  }
  
  void ServerSocket::StartHosting( int port )
  {
       Bind( port );
       Listen();
  }
  
  void ServerSocket::Listen()
  {
      //cout&lt;&lt;"LISTEN FOR CLIENT..."&lt;&lt;endl;
  
      if ( listen ( mySocket, 1 ) == SOCKET_ERROR )
      {
          cerr&lt;&lt;"ServerSocket: Error listening on socket\n";
          system("pause");
          WSACleanup();
          exit(15);
      }
  
      //cout&lt;&lt;"ACCEPT CONNECTION..."&lt;&lt;endl;
  
      acceptSocket = accept( myBackup, NULL, NULL );
      while ( acceptSocket == SOCKET_ERROR )
      {
          acceptSocket = accept( myBackup, NULL, NULL );
      }
      mySocket = acceptSocket;
  }
  
  void ServerSocket::Bind( int port )
  {
      myAddress.sin_family = AF_INET;
      myAddress.sin_addr.s_addr = inet_addr( "0.0.0.0" );
      myAddress.sin_port = htons( port );
  
      //cout&lt;&lt;"BIND TO PORT "&lt;&lt;port&lt;&lt;endl;
  
      if ( bind ( mySocket, (SOCKADDR*) &amp;myAddress, sizeof( myAddress) ) == SOCKET_ERROR )
      {
          cerr&lt;&lt;"ServerSocket: Failed to connect\n";
          system("pause");
          WSACleanup();
          exit(14);
      }
  }
  
  void ClientSocket::ConnectToServer( const char *ipAddress, int port )
  {
      myAddress.sin_family = AF_INET;
      myAddress.sin_addr.s_addr = inet_addr( ipAddress );
      myAddress.sin_port = htons( port );
  
      //cout&lt;&lt;"CONNECTED"&lt;&lt;endl;
  
      if ( connect( mySocket, (SOCKADDR*) &amp;myAddress, sizeof( myAddress ) ) == SOCKET_ERROR )
      {
          cerr&lt;&lt;"ClientSocket: Failed to connect\n";
          system("pause");
          WSACleanup();
          exit(13);
      } 
  
  }
  </code></pre>
  
  <p>And here's stdafx.h</p>
  
  <pre><code>#pragma once
  
  #include "targetver.h"
  
  #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
  // Windows Header Files:
  #include &lt;windows.h&gt;
  
  // C RunTime Header Files
  #include &lt;stdlib.h&gt;
  #include &lt;malloc.h&gt;
  #include &lt;memory.h&gt;
  #include &lt;tchar.h&gt;
  
  
  // TODO: reference additional headers your program requires here
  #include "Socket.h"
  </code></pre>
  
  <p>And here are my error messages:</p>
  
  <pre><code>1&gt;------ Build started: Project: Client, Configuration: Debug Win32 ------
  1&gt;  stdafx.cpp
  1&gt;  Socket.cpp
  1&gt;  Client.cpp
  1&gt;  Generating Code...
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__accept@12 referenced in function "public: void __thiscall ServerSocket::Listen(void)" (?Listen@ServerSocket@@QAEXXZ)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__bind@12 referenced in function "public: void __thiscall ServerSocket::Bind(int)" (?Bind@ServerSocket@@QAEXH@Z)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function "public: void __thiscall Socket::CloseConnection(void)" (?CloseConnection@Socket@@QAEXXZ)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function "public: void __thiscall ClientSocket::ConnectToServer(char const *,int)" (?ConnectToServer@ClientSocket@@QAEXPBDH@Z)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "public: void __thiscall ServerSocket::Bind(int)" (?Bind@ServerSocket@@QAEXH@Z)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function "public: void __thiscall ServerSocket::Bind(int)" (?Bind@ServerSocket@@QAEXH@Z)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__listen@8 referenced in function "public: void __thiscall ServerSocket::Listen(void)" (?Listen@ServerSocket@@QAEXXZ)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__recv@16 referenced in function "public: bool __thiscall Socket::RecvData(char *,int)" (?RecvData@Socket@@QAE_NPADH@Z)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__send@16 referenced in function "public: bool __thiscall Socket::SendData(char *)" (?SendData@Socket@@QAE_NPAD@Z)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)
  1&gt;Socket.obj : error LNK2019: unresolved external symbol __imp__WSACleanup@0 referenced in function "public: __thiscall Socket::Socket(void)" (??0Socket@@QAE@XZ)
  1&gt;C:\Users\ajayp_000\documents\visual studio 2012\Projects\Client\Debug\Client.exe : fatal error LNK1120: 12 unresolved externals
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>