VS 2010 error - cannot open file "iostream"

41,245

Solution 1

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.

Solution 2

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:

Solution 3

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:

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

</Project>

The user property sheet is Microsoft.Cpp.Win32.user.props under <localappdata>\microsoft\msbuild\v4.0 where <localappdata> is c:\users\<username>\appdata\local under Win7.

Share:
41,245

Related videos on Youtube

cpx
Author by

cpx

Updated on October 01, 2020

Comments

  • cpx
    cpx over 3 years

    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
    
    • DumbCoder
      DumbCoder over 13 years
      Does you include path includes the file path for your default header files ?
    • T.E.D.
      T.E.D. over 13 years
      Yeah, CL is the linker. If your compiler can't find that it is messed up. That really makes this more of a sysadmin (Serverfault.com) question than a programming (SO) question.
    • CB Bailey
      CB Bailey over 13 years
      @T.E.D.: No, CL.exe is the compiler in Visual Studio, the linker is named LINK.exe.
    • arkon
      arkon over 11 years
      With all due respect, how the hell does SLaks comment have 11 upvotes? That is entirely unhelpful.
  • Tokunbo Akinola
    Tokunbo Akinola over 12 years
    Great answer Ralf... The major problem here, as we can tell from the error, is that visual studio is not finding the compiler file in your list of executable directories as defined in your property pages. After making sure the "Inherit from parent or project defaults" option is checked, make sure the $(ExecutablePath) shows up at the end of your "Executable Directories" field. That's really all you need. If you modify the individual project settings for each file, you also need to make sure $(ExecutablePath) is added for that project as well.
  • 8bitcartridge
    8bitcartridge almost 11 years
    This worked for me! I'd be agonizing about this for weeks! Thanks!