我刚刚从 VS2005 迁移到 VS2010,它无法编译一个简单的程序.
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;
}
错误 -
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 的经验.
PS: I'm completely new to using VS2010 but have experience in VS 2005.
以下是我从 VS2005 添加到 VS2010 的用户属性表"下的目录列表
Here are lists of directories that I added from VS2005 to VS2010 under 'user property sheet'
可执行 -
$(VCInstallDir)bin; $(VSInstallDir)Common7Toolsin; $(VSInstallDir)Common7 ools; $(VSInstallDir)Common7ide; $(VSInstallDir); $(VSInstallDir)SDKv2.0in
包括 -
$(VCInstallDir)include; $(VCInstallDir)atlmfcinclude; $(FrameworkSDKDir)include
图书馆 -
$(VCInstallDir)lib; $(VCInstallDir)atlmfclib; $(VCInstallDir)atlmfclibi386; $(FrameworkSDKDir)lib; $(VSInstallDir); $(VSInstallDir)lib
来源 -
$(VCInstallDir)atlmfcsrcmfc; $(VCInstallDir)atlmfcsrcmfcm; $(VCInstallDir)atlmfcsrcatl; $(VCInstallDir)crtsrc
我在几台不同的机器上遇到了同样的问题,这些机器已经安装了其他版本的 VS(2005、2008).我最终也收到了各种奇怪的错误.
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.
我发现以下技巧对我有用,也许它也适用于您的情况:- 打开一个新的 VS2010 实例- 使用 def 设置创建新的控制台应用程序.- 尝试编译:应该有一些错误- 打开物业经理"- 调出项目的 Microsoft.Cpp.Win32.user 属性表- 单击 VC++ 目录- 单击可执行目录"字段.那应该显示一个下拉列表,单击下拉列表并选择编辑".您应该会看到一堆继承的值,这些值应该包含与上面列出的目录类似的所有必需目录.取消选中从父级或项目默认值继承"选项.重新检查并单击确定".
- 对包含、库目录等重复此操作.- 点击应用"和确定"- 重建项目并检查它是否有效.
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.
我只需要这样做一次.关闭VS并创建一个新项目后,我就可以编译了.在我发现这一点之前,我手动删除了所有继承的值,并为所有 VS 和 SDK 目录添加了绝对路径.这也有效,但需要做更多的工作.
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.
这篇关于VS 2010 错误 - 无法打开文件“iostream"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!