VS2008与< winsock2.h>的编译错误 [英] VS2008 Compile error with <winsock2.h>

查看:334
本文介绍了VS2008与< winsock2.h>的编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重新定义(105)语法错误,当尝试编译我的VS2008 c ++项目与< winsock2.h> 包括。运行Windows 7 64位。

Getting heaps (105) of redefine & syntax errors when trying to compile my VS2008 c++ project with <winsock2.h> included. Running Windows 7 64bit. I have googled and searched and the answer seems pretty uniform but it doesn't seem to work for me.

尝试了









$ b在之前包括< winsock2.h> #include< windows.h>
。也尝试不包括< windows.h> (因为winsock2包括它自动,如果丢失)。

Tried putting #include <winsock2.h> before #include <windows.h>. Also tried not including <windows.h> (as winsock2 includes it automatically if missing).

#define WIN32_LEAN_AND_MEAN 和/或 #define _WINSOCKAPI _ 之前。

在链接器 - >其他依赖项中,我引用了ws2_32.lib。
也尝试了 #pragma comment(lib,ws2_32.lib)

In the linker -> additional dependencies I have referenced ws2_32.lib. Also tried #pragma comment(lib, "ws2_32.lib").

通常的错误(似乎很多共享):

Usual error (shared by many it seems):

Error   5   error C2011: 'sockaddr' : 'struct' type redefinition    c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h  206 RallyAction
Error   6   error C2143: syntax error : missing '}' before 'constant'   c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h  384 RallyAction
Error   7   error C2143: syntax error : missing ';' before 'constant'   c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h  384 RallyAction
Error   8   error C2059: syntax error : 'constant'  c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h  384 RallyAction

...等等。

任何建议都不胜感激。

推荐答案

结果< windows.h>在项目中的其他位置(单独的.h文件)和上述.h文件之前调用。这是我得到的编码迟到。感谢您的帮助,感谢。

Turns out < windows.h> was called elsewhere in project (separate .h file) and prior to the above .h file. That's what I get for coding late. Thanks for the help, appreciated.

我替换了< windows.h> winsock2.h>,现在工作正常。

I replaced that < windows.h> calling with < winsock2.h> and it's working fine now.

include< mmsystem.h>开始随机给我的问题后,虽然(每隔一个编译)。我得到它与#ifdef _WIN32封装,但仍然似乎随机。保存项目后,最后一次编译成功(每隔一段时间),重新启动VS2008似乎已经固定。该错误是一个内部链接器错误(获得mms lib引用)。

include < mmsystem.h> starting randomly giving me problems after that though (every other compile). I got it encapsulated with #ifdef _WIN32 but still it seems random. Having saved the project after the last time it compiled successfully (every other time) and restarted VS2008 seems to have 'fixed' it. The error was a internal linker error (got the mms lib referenced).

这篇关于VS2008与&lt; winsock2.h&gt;的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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