title: I'm trying to compile a socket program in DevC++ but everytime I do it I get a lot of linker errors like these:
body: <p>I have previously run the socket program successfully in Linux but I have to export it to WindowsXP, and I must admit I'm relatively new to programming in WindowsXP. These are the header files I used in the WindowsXP version</p>
  
  <pre>    
  [Linker error] undefined reference to `WSAStartup@8'
  [Linker error] undefined reference to `htons@4'
  [Linker error] undefined reference to `inet_pton'
  [Linker error] undefined reference to `socket@12'
  </pre>
  
  <pre><code>#define WIN32_LEAN_AND_MEAN
  #include &lt;windows.h&gt;
  //#include &lt;winsock.h&gt;
  #include &lt;winsock2.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ws2tcpip.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  // Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
  #pragma comment (lib, "Ws2_32.lib")
  #pragma comment (lib, "Mswsock.lib")
  #pragma comment (lib, "AdvApi32.lib")
  int main() {
  int iResult;
  WSADATA wsaData;
  // Initialize Winsock
  iResult = WSAStartup(MAKEWORD(2,2), &amp;wsaData);
  if (iResult != 0) {
      printf("WSAStartup failed: %d\n", iResult);
      return 1;
  }
  getch();return 0;}
  </code></pre>
  
  <p>I just found those header files in sample socket programs in the internet and I don't know if I really need all of them, and whether I should use winsock.h or winsock2.h. I also learned that to solve these linker problems I need to link the libraries to the program and that's my main problem now. How do I link the libraries in WindowsXP and make the program in DevC++ work? By the way I'm using C programming language. Please help me solve this problem.</p>