0

我是 Visual C++ 的新手。我在 Windows XP 中安装了 Visual C++ 2008 Express Edition(带有 SP1)。我正在尝试编译一个开源 Visual C++ 项目。

我已经.vcproj在 VC++ 2008 Express 中打开了这个项目。当我使用 Build > Rebuild Solution 时,它显示以下输出:

3 error(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

以下是3个错误:

error C3861: 'IN6_IS_ADDR_MULTICAST': identifier not found

error C2065: 'IPPROTO_IPV6' : undeclared identifier

error C2065: 'IPPROTO_IPV6' : undeclared identifier

我已经在谷歌上搜索了很长时间。我发现这些标识符在以下文件中可用:

  • ws2tcpip.h

  • ws2def.h

  • winsock2.h

如果我没记错的话,Windows 开发人员使用这些文件进行网络/套接字编程。它应该在 Windows 的某个地方可用。

error C2065: undeclared identifier我可以知道和有什么区别error C3861: identifier not found吗?

如何包含ws2tcpip.hws2def.h进入 Visual C++ 2008 项目?

谢谢

4

2 回答 2

1

就像#在适当的文件中包含这些标题一样简单吗?

#include <winsock2.h>
#include <ws2tcpip.h>

请注意,winsock2.h 必须在 ws2tcpip.h之前被#included ,否则您将收到诸如“ip_mreq::imr_multiaddr 使用未定义的 struc in_addr”和“字节不是 in6_addr::__unnamed 的成员”之类的编译错误。

于 2012-08-01T03:29:39.987 回答
0

WIN32_LEAN_AND_MEAN 宏可防止 Winsock.h 包含在 Windows.h 标头中。

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

或添加项目 - 指令 WIN32_LEAN_AND_MEAN

于 2017-07-02T02:20:25.760 回答