简体   繁体   中英

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...

-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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM