- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我已经创建了一个套接字包装类,但是我有太多错误,我无法弄清楚如何解决。我试过Winsock tutorial error和 Can't include Winsock2.h in MSVC 2010 ,但没用
代码如下:
//#define WIN32_LEAN_AND_MEAN
#include <iostream>
#include <string>
#include <Windows.h>
#include <WinSock2.h>
#include <WS2tcpip.h>
#pragma comment(lib,"ws2_32_lib")
using namespace std;
#define WM_SOCKET 0x10000
class Socket
{
};
以下是错误:
Error 107 error C3861: 'WSAStartup': identifier not found \85 1 Project2_SocketLib
Error 89 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 696 1 Project2_SocketLib
Error 90 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 703 1 Project2_SocketLib
Error 91 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 742 1 Project2_SocketLib
Error 92 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 749 1 Project2_SocketLib
Error 93 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 793 1 Project2_SocketLib
Error 94 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 800 1 Project2_SocketLib
Error 95 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 841 1 Project2_SocketLib
Error 96 error C3861: 'WSASetLastError': identifier not found C:\Program Files (x86)\Windows Kits\8.0\Include\um\WS2tcpip.h 848 1 Project2_SocketLib
Error 109 error C3861: 'WSAGetLastError': identifier not found \87 1 Project2_SocketLib
Error 112 error C3861: 'WSAGetLastError': identifier not found \93 1 Project2_SocketLib
Error 105 error C3861: 'WSACleanup': identifier not found \63 1 Project2_SocketLib
Error 103 error C3861: 'shutdown': identifier not found \57 1 Project2_SocketLib
Error 100 error C3861: 'send': identifier not found \37 1 Project2_SocketLib
Error 101 error C3861: 'send': identifier not found \43 1 Project2_SocketLib
Error 98 error C3861: 'recv': identifier not found \31 1 Project2_SocketLib
Error 99 error C3861: 'recv': identifier not found \34 1 Project2_SocketLib
Error 116 error C3861: 'inet_ntoa': identifier not found \115 1 Project2_SocketLib
Error 119 error C3861: 'htons': identifier not found \137 1 Project2_SocketLib
Error 126 error C3861: 'htonl': identifier not found \139 1 Project2_SocketLib
Error 104 error C3861: 'closesocket': identifier not found \58 1 Project2_SocketLib
Error 102 error C3861: 'accept': identifier not found \50 1 Project2_SocketLib
Error 6 error C3805: 'constant': unexpected token, expected either '}' or a ',' C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h 414 1 Project2_SocketLib
Error 108 error C2568: '+' : unable to resolve function overload \87 1 Project2_SocketLib
Error 111 error C2568: '+' : unable to resolve function overload \93 1 Project2_SocketLib
Error 124 error C2568: ':' : unable to resolve function overload \139 1 Project2_SocketLib
Error 125 error C2446: ':' : no conversion from 'unsigned long (__stdcall *)(const char *)' to 'u_long (__stdcall *)(u_long)' \139 1 Project2_SocketLib
Error 106 error C2440: '=' : cannot convert from 'WSADATA' to 'int' \75 1 Project2_SocketLib
Error 110 error C2440: '=' : cannot convert from 'SOCKET (__stdcall *)(int,int,int)' to 'SOCKET' \90 1 Project2_SocketLib
Error 115 error C2440: '=' : cannot convert from 'char *(__stdcall *)(in_addr)' to 'std::string' \115 1 Project2_SocketLib
Error 66 error C2375: 'WSAUnhookBlockingHook' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2383 1 Project2_SocketLib
Error 61 error C2375: 'WSAStartup' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2296 1 Project2_SocketLib
Error 63 error C2375: 'WSASetLastError' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2332 1 Project2_SocketLib
Error 67 error C2375: 'WSASetBlockingHook' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2400 1 Project2_SocketLib
Error 65 error C2375: 'WSAIsBlocking' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2366 1 Project2_SocketLib
Error 64 error C2375: 'WSAGetLastError' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2349 1 Project2_SocketLib
Error 62 error C2375: 'WSACleanup' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2315 1 Project2_SocketLib
Error 68 error C2375: 'WSACancelBlockingCall' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2417 1 Project2_SocketLib
Error 75 error C2375: 'WSACancelAsyncRequest' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2592 1 Project2_SocketLib
Error 76 error C2375: 'WSAAsyncSelect' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2612 1 Project2_SocketLib
Error 70 error C2375: 'WSAAsyncGetServByPort' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2466 1 Project2_SocketLib
Error 69 error C2375: 'WSAAsyncGetServByName' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2439 1 Project2_SocketLib
Error 72 error C2375: 'WSAAsyncGetProtoByNumber' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2517 1 Project2_SocketLib
Error 71 error C2375: 'WSAAsyncGetProtoByName' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2492 1 Project2_SocketLib
Error 73 error C2375: 'WSAAsyncGetHostByName' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2542 1 Project2_SocketLib
Error 74 error C2375: 'WSAAsyncGetHostByAddr' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2569 1 Project2_SocketLib
Error 53 error C2375: 'socket' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2120 1 Project2_SocketLib
Error 52 error C2375: 'shutdown' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2099 1 Project2_SocketLib
Error 51 error C2375: 'setsockopt' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2077 1 Project2_SocketLib
Error 50 error C2375: 'sendto' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2051 1 Project2_SocketLib
Error 49 error C2375: 'send' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2026 1 Project2_SocketLib
Error 48 error C2375: 'select' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2002 1 Project2_SocketLib
Error 47 error C2375: 'recvfrom' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1976 1 Project2_SocketLib
Error 46 error C2375: 'recv' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1951 1 Project2_SocketLib
Error 45 error C2375: 'ntohs' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1931 1 Project2_SocketLib
Error 44 error C2375: 'ntohl' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1914 1 Project2_SocketLib
Error 43 error C2375: 'listen' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1896 1 Project2_SocketLib
Error 35 error C2375: 'ioctlsocket' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1658 1 Project2_SocketLib
Error 42 error C2375: 'inet_ntoa' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1795 1 Project2_SocketLib
Error 41 error C2375: 'inet_addr' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1778 1 Project2_SocketLib
Error 40 error C2375: 'htons' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1761 1 Project2_SocketLib
Error 39 error C2375: 'htonl' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1744 1 Project2_SocketLib
Error 38 error C2375: 'getsockopt' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1723 1 Project2_SocketLib
Error 37 error C2375: 'getsockname' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1700 1 Project2_SocketLib
Error 57 error C2375: 'getservbyport' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2221 1 Project2_SocketLib
Error 58 error C2375: 'getservbyname' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2240 1 Project2_SocketLib
Error 59 error C2375: 'getprotobynumber' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2258 1 Project2_SocketLib
Error 60 error C2375: 'getprotobyname' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2275 1 Project2_SocketLib
Error 36 error C2375: 'getpeername' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1679 1 Project2_SocketLib
Error 56 error C2375: 'gethostname' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2181 1 Project2_SocketLib
Error 55 error C2375: 'gethostbyname' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2163 1 Project2_SocketLib
Error 54 error C2375: 'gethostbyaddr' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 2144 1 Project2_SocketLib
Error 34 error C2375: 'connect' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1637 1 Project2_SocketLib
Error 33 error C2375: 'closesocket' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1618 1 Project2_SocketLib
Error 32 error C2375: 'bind' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1599 1 Project2_SocketLib
Error 31 error C2375: 'accept' : redefinition; different linkage C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 1577 1 Project2_SocketLib
Error 118 error C2228: left of '.sin_port' must have class/struct/union \137 1 Project2_SocketLib
Error 120 error C2228: left of '.sin_family' must have class/struct/union \138 1 Project2_SocketLib
Error 121 error C2228: left of '.sin_addr' must have class/struct/union \139 1 Project2_SocketLib
Error 122 error C2228: left of '.S_un' must have class/struct/union \139 1 Project2_SocketLib
Error 123 error C2228: left of '.S_addr' must have class/struct/union \139 1 Project2_SocketLib
Error 114 error C2227: left of '->sin_addr' must point to class/struct/union/generic type \115 1 Project2_SocketLib
Error 97 error C2079: 'Socket::wsaData' uses undefined struct 'WSAData' \18 1 Project2_SocketLib
Error 117 error C2079: 'sockAddrIn' uses undefined struct 'sockaddr_in' \135 1 Project2_SocketLib
Error 78 error C2079: 'sockaddr_gen::AddressIn' uses undefined struct 'sockaddr_in' C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2ipdef.h 81 1 Project2_SocketLib
Error 77 error C2079: 'sockaddr_gen::Address' uses undefined struct 'sockaddr' C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2ipdef.h 80 1 Project2_SocketLib
Error 87 error C2079: '_SOCKADDR_INET::Ipv4' uses undefined struct 'sockaddr_in' C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2ipdef.h 202 1 Project2_SocketLib
Error 5 error C2059: syntax error : 'constant' C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h 414 1 Project2_SocketLib
Error 113 error C2027: use of undefined type 'sockaddr_in' \115 1 Project2_SocketLib
Error 21 error C2011: 'WSAData' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 353 1 Project2_SocketLib
Error 16 error C2011: 'timeval' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 169 1 Project2_SocketLib
Error 22 error C2011: 'sockproto' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 451 1 Project2_SocketLib
Error 12 error C2011: 'sockaddr_in' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h 608 1 Project2_SocketLib
Error 4 error C2011: 'sockaddr' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h 217 1 Project2_SocketLib
Error 19 error C2011: 'servent' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 245 1 Project2_SocketLib
Error 20 error C2011: 'protoent' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 257 1 Project2_SocketLib
Error 18 error C2011: 'netent' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 238 1 Project2_SocketLib
Error 23 error C2011: 'linger' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 493 1 Project2_SocketLib
Error 88 error C2011: 'ip_mreq' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2ipdef.h 715 1 Project2_SocketLib
Error 17 error C2011: 'hostent' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 225 1 Project2_SocketLib
Error 13 error C2011: 'fd_set' : 'struct' type redefinition C:\Program Files (x86)\Windows Kits\8.0\Include\um\WinSock2.h 125 1 Project2_SocketLib
Error 127 error C1003: error count exceeds 100; stopping compilation \139 1 Project2_SocketLib
最佳答案
您需要像这样重新排序 Windows header 的包含:
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <Windows.h>
换句话说,WinSock header 必须包含在 Windows.h
之前。
或定义您出于某种原因注释掉的 WIN32_LEAN_AND_MEAN
。
我认为您还需要更改 Accept
方法以返回 SOCKET
而不是 Socket
。
#pragma
应该是:
#pragma comment(lib,"ws2_32")
关于c++ - 套接字错误无法在 WinSock2.h 中获取函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22517036/
我通过 spring ioc 编写了一些 Rest 应用程序。但我无法解决这个问题。这是我的异常(exception): org.springframework.beans.factory.BeanC
我对 TestNG、Spring 框架等完全陌生,我正在尝试使用注释 @Value通过 @Configuration 访问配置文件注释。 我在这里想要实现的目标是让控制台从配置文件中写出“hi”,通过
为此工作了几个小时。我完全被难住了。 这是 CS113 的实验室。 如果用户在程序(二进制计算器)结束时选择继续,我们需要使用 goto 语句来到达程序的顶部。 但是,我们还需要释放所有分配的内存。
我正在尝试使用 ffmpeg 库构建一个小的 C 程序。但是我什至无法使用 avformat_open_input() 打开音频文件设置检查错误代码的函数后,我得到以下输出: Error code:
使用 Spring Initializer 创建一个简单的 Spring boot。我只在可用选项下选择 DevTools。 创建项目后,无需对其进行任何更改,即可正常运行程序。 现在,当我尝试在项目
所以我只是在 Mac OS X 中通过 brew 安装了 qt。但是它无法链接它。当我尝试运行 brew link qt 或 brew link --overwrite qt 我得到以下信息: ton
我在提交和 pull 时遇到了问题:在提交的 IDE 中,我看到: warning not all local changes may be shown due to an error: unable
我跑 man gcc | grep "-L" 我明白了 Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more inf
我有一段代码,旨在接收任何 URL 并将其从网络上撕下来。到目前为止,它运行良好,直到有人给了它这个 URL: http://www.aspensurgical.com/static/images/a
在过去的 5 个小时里,我一直在尝试在我的服务器上设置 WireGuard,但在完成所有设置后,我无法 ping IP 或解析域。 下面是服务器配置 [Interface] Address = 10.
我正在尝试在 GitLab 中 fork 我的一个私有(private)项目,但是当我按下 fork 按钮时,我会收到以下信息: No available namespaces to fork the
我这里遇到了一些问题。我是 node.js 和 Rest API 的新手,但我正在尝试自学。我制作了 REST API,使用 MongoDB 与我的数据库进行通信,我使用 Postman 来测试我的路
下面的代码在控制台中给出以下消息: Uncaught DOMException: Failed to execute 'appendChild' on 'Node': The new child el
我正在尝试调用一个新端点来显示数据,我意识到在上一组有效的数据中,它在数据周围用一对额外的“[]”括号进行控制台,我认为这就是问题是,而新端点不会以我使用数据的方式产生它! 这是 NgFor 失败的原
我正在尝试将我的 Symfony2 应用程序部署到我的 Azure Web 应用程序,但遇到了一些麻烦。 推送到远程时,我在终端中收到以下消息 remote: Updating branch 'mas
Minikube已启动并正在运行,没有任何错误,但是我无法 curl IP。我在这里遵循:https://docs.traefik.io/user-guide/kubernetes/,似乎没有提到关闭
每当我尝试docker组成任何项目时,都会出现以下错误。 我尝试过有和没有sudo 我在这台机器上只有这个问题。我可以在Mac和Amazon WorkSpace上运行相同的容器。 (myslabs)
我正在尝试 pip install stanza 并收到此消息: ERROR: No matching distribution found for torch>=1.3.0 (from stanza
DNS 解析看起来不错,但我无法 ping 我的服务。可能是什么原因? 来自集群中的另一个 Pod: $ ping backend PING backend.default.svc.cluster.l
我正在使用Hibernate 4 + Spring MVC 4当我开始 Apache Tomcat Server 8我收到此错误: Error creating bean with name 'wel
我是一名优秀的程序员,十分优秀!