简体   繁体   English

无法使用Visual C ++编译器包含某些头文件

[英]Cannot include certain header files using the Visual C++ compiler

Hello I'm getting into Winsock programming in C. I believe that in order for me to access the (or any other header related to Winsock for that matter) header file I have to have Visual C++ 2010 installed and set it as my default compiler. 您好,我正在使用C进行Winsock编程。我相信,为了访问我(或与Winsock相关的任何其他标头)标头文件,我必须安装Visual C ++ 2010并将其设置为默认编译器。 So I download it, and in CodeBlocks I set it to my compiler. 因此,我将其下载,并在CodeBlocks中将其设置为编译器。 I run some Winsock code and I get this message: 我运行一些Winsock代码,并收到以下消息:

C:\Users\Jared\Documents\Test.c|6|fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory|

I also get this message for including 'winsock.h' and 'windows.h'. 我也收到包含“ winsock.h”和“ windows.h”的消息。 This has something to do with the Visual C++ compiler. 这与Visual C ++编译器有关。 I try installing Visual C++ 2008 and use it as my compiler and get the same message. 我尝试安装Visual C ++ 2008,并将其用作编译器,并得到相同的消息。 I then read that I have to install microsoft's SDK. 然后,我读到我必须安装微软的SDK。 I download and install it and it gets an error saying that I can't install it (this is the .Net framework 4.0 version). 我下载并安装它,并收到一条错误消息,提示我无法安装(这是.Net Framework 4.0版本)。 I then try the 3.5 version and it installs fine but my compiler still can't find the header files. 然后,我尝试使用3.5版,它可以很好地安装,但是我的编译器仍然找不到头文件。 I have the .net framework 4.0 so I don't see the problem. 我有.net Framework 4.0,所以看不到问题。 I also read that I have to include some header files in Visual C++ by going to Tools>Options>Projects and Solutions>VC++ Directories and I get the following message: 我还读到我必须在Visual C ++中包含一些头文件,方法是转到“工具”>“选项”>“项目和解决方案”>“ VC ++目录”,然后得到以下消息:

"VC++ Directory editing in tools > options has been deprecated."

Visual C++ 2010 no longer supports this feature. Visual C ++ 2010不再支持此功能。 Does anyone have a solution or can help me with this? 有没有人有解决方案或可以帮助我吗?

Long story short: I cannot include 'winsock.h', 'winsock2.h', or 'windows.h' using the Visual C++ 2010 compiler. 长话短说:我不能使用Visual C ++ 2010编译器包含“ winsock.h”,“ winsock2.h”或“ windows.h”。

All help is appreciated. 感谢所有帮助。

In Visual C++ 2010 it is recommended to use property sheets instead of this kind of global directory settings editing. 在Visual C ++ 2010中,建议使用属性表代替这种全局目录设置编辑。 You need to edit the user settings property sheet (probably Microsoft.Cpp.Win32.user.props ) in your AppData folder. 您需要在AppData文件夹中编辑用户设置属性表(可能是Microsoft.Cpp.Win32.user.props )。 You can do it in the UI through the Property Manager via View->Property Manager and browsing for that sheet. 您可以通过“视图”->“属性管理器”中的“属性管理器”在UI中进行操作,然后浏览该工作表。

However, I think you should have $(WindowsSdkDir)include in Include Directories if you have it installed correctly. 但是,如果安装正确,我认为您应该在包含目录中包含$(WindowsSdkDir)include

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM