C++ Windows 中 UDP 的头文件?
我有一个通过 UDP 协议发送数据的 Linux 应用程序。它使用这些头文件:
#include <stdio.h>
/* standard C i/o facilities */
#include <stdlib.h>
/* needed for atoi() */
#include <unistd.h>
/* defines STDIN_FILENO, system calls,etc */
#include <sys/types.h> /* system data type definitions */
#include <sys/socket.h> /* socket specific definitions */
#include <netinet/in.h> /* INET constants and stuff */
#include <arpa/inet.h> /* IP address conversion stuff */
#include <netdb.h>
#include <string.h> /* for string and memset etc */
/* gethostbyname */
#include <iostream>
#include <fstream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
我想制作我的应用程序的 WIndows 版本。但是上面的一些头文件在WIndows中不起作用,尤其是UDP的头文件。
在 Windows (Visual Studio 2010) 中我应该用哪些头文件替换它们?
更新:
好的,我的标题现在看起来像这样:
#include <iostream>
#include <fstream>
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <winsock2.h>
尝试编译时出现此错误(以及许多其他类似的错误):
Error 13 error C2011: 'fd_set' : 'struct' type redefinition c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock2.h 132 1 Client
I have a linux applications which sends data over UDP protocol. It uses these header files:
#include <stdio.h>
/* standard C i/o facilities */
#include <stdlib.h>
/* needed for atoi() */
#include <unistd.h>
/* defines STDIN_FILENO, system calls,etc */
#include <sys/types.h> /* system data type definitions */
#include <sys/socket.h> /* socket specific definitions */
#include <netinet/in.h> /* INET constants and stuff */
#include <arpa/inet.h> /* IP address conversion stuff */
#include <netdb.h>
#include <string.h> /* for string and memset etc */
/* gethostbyname */
#include <iostream>
#include <fstream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
I want to make a WIndows version of my app. But some of the above header files do not work in WIndows, especially those for UDP.
Which header files should I substitute them for in Windows (Visual Studio 2010)?
UPDATE:
Ok, so my header now looks like this:
#include <iostream>
#include <fstream>
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <winsock2.h>
I get this error when trying to compile (and many other similar errors):
Error 13 error C2011: 'fd_set' : 'struct' type redefinition c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winsock2.h 132 1 Client
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在编译时,您需要使用
Winsock2.h
而不是 Unix 标头。在链接时,包含
ws2_32.lib
以提供到所需系统 DLL 的链接。At compile-time, you need to use
Winsock2.h
instead of the Unix headers.At link-time, include
ws2_32.lib
to provide linkage to the required system DLL.注释掉“丢失”的包含文件
或将它们放入以下内容:
Comment out the include files that are "missing"
or put them into the following:
您不需要其中的大部分内容。您需要的唯一文件是 winsock2.h 并链接到 ws2_32.lib。
因此,对于所有网络内容,只需包含 winsock2.h。
You don't need most of those includes. The only file you will need is winsock2.h and link with ws2_32.lib.
So, for all networking stuff, just include winsock2.h.
您想要#includewinsock2.h。一个特点是,您需要在包含其他任何内容之前#include,包括:
You want to #include winsock2.h. One peculiarity, you need to #include before including anything else, including :