VS 2010 错误 - 无法打开文件“iostream”
我刚刚从 VS2005 迁移到 VS2010,但无法编译一个简单的程序。
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Hello Visual Studio 2010 :)" << endl;
}
错误 -
1 error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified.
2 IntelliSense: cannot open source file "iostream"
3 IntelliSense: name followed by '::' must be a class or namespace name
4 IntelliSense: name followed by '::' must be a class or namespace name
5 IntelliSense: identifier "cout" is undefined
6 IntelliSense: identifier "endl" is undefined
PS:我对使用 VS2010 完全陌生,但有 VS 2005 的经验。
以下是我在“用户属性表”下从 VS2005 添加到 VS2010 的目录列表'
可执行文件 -
$(VCInstallDir)bin; $(VSInstallDir)Common7\Tools\bin; $(VSInstallDir)Common7\tools; $(VSInstallDir)Common7\ide; $(VSInstallDir); $(VSInstallDir)\SDK\v2.0\bin
包含 -
$(VCInstallDir)include; $(VCInstallDir)atlmfc\include; $(FrameworkSDKDir)include
库 -
$(VCInstallDir)lib; $(VCInstallDir)atlmfc\lib; $(VCInstallDir)atlmfc\lib\i386; $(FrameworkSDKDir)lib; $(VSInstallDir); $(VSInstallDir)lib
来源 -
$(VCInstallDir)atlmfc\src\mfc; $(VCInstallDir)atlmfc\src\mfcm; $(VCInstallDir)atlmfc\src\atl; $(VCInstallDir)crt\src
I've just migrated from VS2005 to VS2010 and it fails to compile a simple program.
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Hello Visual Studio 2010 :)" << endl;
}
Errors -
1 error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified.
2 IntelliSense: cannot open source file "iostream"
3 IntelliSense: name followed by '::' must be a class or namespace name
4 IntelliSense: name followed by '::' must be a class or namespace name
5 IntelliSense: identifier "cout" is undefined
6 IntelliSense: identifier "endl" is undefined
PS: I'm completely new to using VS2010 but have experience in VS 2005.
Here are lists of directories that I added from VS2005 to VS2010 under 'user property sheet'
Executable -
$(VCInstallDir)bin; $(VSInstallDir)Common7\Tools\bin; $(VSInstallDir)Common7\tools; $(VSInstallDir)Common7\ide; $(VSInstallDir); $(VSInstallDir)\SDK\v2.0\bin
Include -
$(VCInstallDir)include; $(VCInstallDir)atlmfc\include; $(FrameworkSDKDir)include
Library -
$(VCInstallDir)lib; $(VCInstallDir)atlmfc\lib; $(VCInstallDir)atlmfc\lib\i386; $(FrameworkSDKDir)lib; $(VSInstallDir); $(VSInstallDir)lib
Source -
$(VCInstallDir)atlmfc\src\mfc; $(VCInstallDir)atlmfc\src\mfcm; $(VCInstallDir)atlmfc\src\atl; $(VCInstallDir)crt\src
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在几台不同的机器上遇到了同样的问题,其中已经安装了其他版本的 VS(2005、2008)。我最终也遇到了各种奇怪的错误。
我发现以下技巧对我有用,也许它也适用于您的情况:
- 打开VS2010的新实例
- 使用默认设置创建新的控制台应用程序。
- 尝试编译:应该有一些错误
- 打开“物业管理器”
- 调出项目的Microsoft.Cpp.Win32.user属性表
- 单击 VC++ 目录
- 单击“可执行目录”字段。这应该显示一个下拉菜单,单击下拉菜单并选择“编辑”。您应该看到一堆继承的值,这些值应该包含与上面列出的目录类似的所有必需目录。取消选中“从父级或项目默认值继承”选项。重新检查并单击“确定”。
- 对包含、库目录等重复此操作。
- 单击“应用”和“确定”
- 重建项目并检查这是否有效。
我只需要这样做一次。关闭VS并创建一个新项目后,我就可以编译了。在发现这一点之前,我手动删除了所有继承的值并添加了所有 VS 和 SDK 目录的绝对路径。这也有效,但工作量更大。
I've run into the same issue on a couple of different machines where there were other versions of VS (2005, 2008) already installed. I ended up also getting all sorts of strange errors.
I found the following trick worked for me, maybe it will work in your case too:
- Open a new instance of VS2010
- Create new console application with the def settings.
- Try compile: there should be some errors
- Open the "Property Manager"
- Bring up the Microsoft.Cpp.Win32.user property sheet of the project
- Click on VC++ Directories
- Click on the "Executable Directories" field. That should display a drop down, click on the drop down and select "Edit". You should see a bunch of inherited values that supposedly contain all the required directories similar to the ones you listed above. Uncheck the "Inherit from parent or project defaults" option. Recheck it and click "Ok".
- Repeat this for the includes, library directories, etc.
-Click on "Apply" and "Ok"
- Rebuild the project and check if this worked.
I only needed to do this once. After closing VS and creating a new project, I could just compile. Before I discovered this, I manually removed all inherited values and added absolute paths to all the VS and SDK directories. That also worked, but was a lot more work.
系统找不到 Visual C++ 编译器 (CL.exe)...
您应该尝试的操作:
重新运行 Visual Studio 2010 安装程序并确保选择安装适合您的平台(x86 或 amd64)的 Visual C++ 工具.
在修复模式下运行安装程序。
如果这不能解决您的问题:
The system could not find the Visual C++ compiler (CL.exe)...
Things you should try:
Rerun the Visual Studio 2010 installer and make sure you selected to install Visual C++ tools for your platform (either x86 or amd64).
Run the installer in repair mode.
If this does not solve your problem:
我遇到了同样的问题,通过搜索找到了这个页面,但我不太明白拉尔夫关于用户属性表的回答,并且没有重新安装。我认为拉尔夫的答案对我有用,但我正在查看当您右键单击解决方案资源管理器中的项目并选择“属性”时出现的“属性页”对话框。没想到这和“物业经理”有什么不同。
因此,我在 msdn 论坛上询问并得到 答案和对属性表的很好的解释。对我有用的解决方案是在文本编辑器中编辑用户属性表并删除所有路径,将其保留为空,如下所示:
用户属性表为 Microsoft.Cpp.Win32.user.props在下面
\microsoft\msbuild\v4.0
其中
是Win7下的
c:\users\<用户名>\appdata\local
。I had the same problem and found this page via a search, but I didn't quite grasp Ralf's answer about the user property sheet, and had no luck with re-installing. I think Ralf's answer would have worked for me, but I was looking at the "Property Pages" dialog that comes up when you right-click on a project in the Solution Explorer and choose "Properties". I didn't realize that it was different from the "Property Manager".
So, I asked on the msdn forum and got an answer and a nice explanation of property sheets. The solution that worked for me was to edit the user property sheet in a text editor and delete all the paths, leaving it empty like this:
The user property sheet is
Microsoft.Cpp.Win32.user.props
under<localappdata>\microsoft\msbuild\v4.0
where<localappdata>
isc:\users\<username>\appdata\local
under Win7.我不知道为什么这有效,但我收到此错误并安装 Visual Studio电源命令为我解决了这个问题。此扩展添加了配置属性 -> VC++ 目录允许您直接修改 ExecutableDirectories 宏,它可能与此有关。
I have no idea why this worked but I was getting this error and installing Visual Studio Power Commands solved this for me. This extension adds the Configuration Properties -> VC++ Directories that allows you to directly modify the ExecutableDirectories macro, it might have something to do with that.