简体   繁体   English

cygwin + Windows套接字编程

[英]cygwin + Windows socket programming

I am trying to learn Socket programming in Windows and am using cygwin for the same. 我正在尝试学习Windows中的Socket编程,并且正在使用cygwin。 I found out that the required files needed for the same were at /usr/include/w32api/ . 我发现相同所需的文件位于/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 ..... 我在cygwin环境中使用gcc-3编译它并得到非常奇怪的错误.....

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... 我也尝试使用winsock2而不是winsock.h,但错误仍然存​​在......

-lws2_32 should do it. -lws2_32应该这样做。

However, Cygwin has its own POSIX-compatible socket implementation on top of winsock, and mixing things up generally is not a good idea. 但是,Cygwin在winsock之上有自己的POSIX兼容套接字实现,通常混合起来并不是一个好主意。 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. 如果你想坚持使用winsock,你可能想要使用gcc-3的-mno-cygwin选项,它将Cygwin DLL排除在等式之外。 (You'll also need to drop w32api/ from the #include lines.) (您还需要从#include行中删除w32api/ 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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