user506710
user506710

Reputation:

cygwin + Windows socket programming

I am trying to learn Socket programming in Windows and am using cygwin for the same. I found out that the required files needed for the same were at /usr/include/w32api/.

I took a sample program from net and tried to compile but was unable to do so.... The code for the same is

 #include <w32api/windows.h>
 #include <w32api/winsock.h>
 #include <stdio.h>
  int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
  {

       WORD sockVersion;
           WSADATA wsaData;
           int nret;

        sockVersion = MAKEWORD(1, 1);           // We'd like Winsock version 1.1

        // We begin by initializing Winsock

        WSAStartup(sockVersion, &wsaData);

       // rest part of code
   }

I compile it using gcc-3 in cygwin environment and get very strange errors .....

undefined reference to '_WSAStartup08' and many such errors...

I have taken the code from a tutorial site and thus would like to know what am i dng wrong and how should i run the program.

Thanks a lot..

edit ---------

I have also tried to use winsock2 instead of winsock.h but the errors persist...

Upvotes: 5

Views: 4284

Answers (1)

ak2
ak2

Reputation: 6778

-lws2_32 should do it.

However, Cygwin has its own POSIX-compatible socket implementation on top of winsock, and mixing things up generally is not a good idea. If you want to stick with winsock, you probably want to use gcc-3's -mno-cygwin option that takes the Cygwin DLL out of the equation. (You'll also need to drop w32api/ from the #include lines.)

Upvotes: 6

Related Questions