在哪里可以得到“sys / socket.h”标题/源文件? [英] Where does one get the "sys/socket.h" header/source file?

查看:3786
本文介绍了在哪里可以得到“sys / socket.h”标题/源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试用C ++ Unix风格编写一个服务器,但我坚持在Windows机器上。我从MinGW开始,但它没有编译正确,告诉我,它找不到sys / socket.h文件。当然,这是服务器甚至工作所必需的。我去寻找它,我想在某个地方说安装Cygwin,因为它带有很多图书馆。好吧,所以我安装它。每一个图书馆它可能提供给我。然后我去再次编译,它STILL找不到它。我通过ENTIRE包含文件夹搜索,找不到该文件。所以我有点iff ed(3小时下来的额外的功能,我不需要),但我继续搜索。我找不到它任何地方。我发现多个引用使用它,但我找不到任何地方下载它。我一直在寻找过去几个小时现在,我已经变得非常沮丧的一切,因为没有引用我可以得到它(我不会使用winsock。如果我记得正确的话,打破兼容性) / p>

所以,长故事,在哪里可以下载socket.h/'socket.c'/'socket.cpp文件?

解决方案

p>由于Windows没有sys / socket.h,你可能会考虑这样做:

  #ifdef __WIN32__ 
#include< winsock2.h>
#else
#include< sys / socket.h>
#endif

我知道你表示不会使用WinSock,是TCP如何在Windows下完成网络,我没有看到你有任何替代方案。即使您使用跨平台网络库,该库也会在内部调用WinSock。大多数标准的BSD套接字API调用是在WinSock中实现的,所以有了一点点,你可以使相同的基于套接字的程序在Windows和其他操作系统下编译。只要不要忘记做一个

  #ifdef __WIN32__ 
WORD versionWanted = MAKEWORD(1,1);
WSADATA wsaData;
WSAStartup(versionWanted,& wsaData); main()顶部的
#endif

...否则所有套接字调用将在Windows下失败,因为WSA子系统未为您的进程初始化。


I've been trying to write a server in C++ Unix style, but I'm stuck on a Windows machine. I started with MinGW, but it didn't compile right and told me that it couldn't find the "sys/socket.h" file. Which, of course, is necessary for the server to even work. I went searching for it, and I think somewhere said to install Cygwin instead, as it comes with lots of libraries. Okay, so I installed it. Every single library it could possibly offer me. Then I went to compile again, and it STILL can't find it. I went searching through the ENTIRE includes folder, and couldn't find the file. So I was a little miffed (3 hours down the drain for extra functionality I don't need), but I continued to search. I can't find it ANYWHERE. I find multiple references to using it, but I can't find ANYWHERE to download it. I've been searching for the past few hours now, and I've become very frustrated with everything because there are NO references to where I can get it (and I will NOT use winsock. That breaks compatibility if I remember right).

So, long story short, where can I download the 'socket.h'/'socket.c'/'socket.cpp' files? It would make my life (and I'm sure many others' lives) SO much easier, and I would really appreciate it!

解决方案

Given that Windows has no sys/socket.h, you might consider just doing something like this:

#ifdef __WIN32__
# include <winsock2.h>
#else
# include <sys/socket.h>
#endif

I know you indicated that you won't use WinSock, but since WinSock is how TCP networking is done under Windows, I don't see that you have any alternative. Even if you use a cross-platform networking library, that library will be calling WinSock internally. Most of the standard BSD sockets API calls are implemented in WinSock, so with a bit of futzing around, you can make the same sockets-based program compile under both Windows and other OS's. Just don't forget to do a

#ifdef __WIN32__
   WORD versionWanted = MAKEWORD(1, 1);
   WSADATA wsaData;
   WSAStartup(versionWanted, &wsaData);
#endif

at the top of main()... otherwise all of your socket calls will fail under Windows, because the WSA subsystem wasn't initialized for your process.

这篇关于在哪里可以得到“sys / socket.h”标题/源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆