title: undefined reference to `__imp_WSACleanup'
body: <p>This is my first program with winsock. As you can see, I've <code>#include &lt;winsock2.h&gt;</code> and linked <code>ws2_32.dll</code>, but the code still doesn't compile:</p>
  
  <pre><code>#include&lt;winsock2.h&gt;
  #pragma comment(lib, "ws2_32")
  class CInitSock{
  public:
  
      CInitSock(BYTE minorVer=2,BYTE majorVer=2){
          //initialize WS2_32.dll
          WSADATA wsaData;
          WORD sockVersion = MAKEWORD(minorVer,majorVer);
          if(::WSAStartup(sockVersion,&amp;wsaData)!=0){
              exit(0);
          }
      }
      //release winSock libary
      ~CInitSock(){
          ::WSACleanup();
      } 
  };
  
  #include "CInitSock.h"
  #include&lt;stdio.h&gt;
  CInitSock initSock;
  int main(void){
      char szHost[256];
      ::gethostname(szHost,256);
      hostent *phost = ::gethostbyname(szHost);
      in_addr addr;
      for(int i = 0;;i++){
          char *p = phost-&gt;h_addr_list[i];
          if(p==NULL){
              break;
          } 
          memcpy(&amp;addr.S_un.S_addr,p,phost-&gt;h_length);
          char *szIp = ::inet_ntoa(addr);
          printf("%s \n",szIp);   
      }
  }
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>mingw32-make.exe -f "D:\project\c_program\Makefile.win" all
  g++.exe GetAllIPs.o -o win_socket.exe -L"D:/tools/develepment/Dev-Cpp/MinGW64/x86_64- w64-mingw32/lib" -L"D:/tools/develepment/Dev-Cpp/MinGW64/lib32" -static-libgcc -mwindows -g3
  
  
  GetAllIPs.o: In function `main':
  D:\project\c_program/GetAllIPs.cpp:6: undefined reference to `__imp_gethostname'
  D:\project\c_program/GetAllIPs.cpp:7: undefined reference to `__imp_gethostbyname'
  D:\project\c_program/GetAllIPs.cpp:15: undefined reference to `__imp_inet_ntoa'
  GetAllIPs.o: In function `CInitSock::CInitSock(unsigned char, unsigned char)':
  D:\project\c_program/CInitSock.h:10: undefined reference to `__imp_WSAStartup'
  GetAllIPs.o: In function `CInitSock::~CInitSock()':
  D:\project\c_program/CInitSock.h:16: undefined reference to `__imp_WSACleanup'
  collect2.exe: error: ld returned 1 exit status
  
  mingw32-make.exe: *** [win_socket.exe] Error 1
  </code></pre>
  
  <p>Now I'm totally confused...</p>