"Error C1083: Cannot open source file" Shouldn't Be Looking For The File At All

I was trying to #include a cpp file with some functions so I can use that cpp file later with other projects. It gave me an 'already defined in .obj' error and since then that .cpp file was like binded with my project. (I understood that's not the way, the answer here helped me with the already defined)

If I exclude the .cpp file from the project, remove it from the directory and remove the #include line it still looks for it:

c1xx : fatal error C1083: Cannot open source file: 'std.cpp': No such file or directory



It shouldn't be looking for the std.cpp at all, I removed it! So is there a way I can reset the project and recompile so that the program doesn't look for it? I already tried Rebuild and Clear -> Build Project

When I ran across a similar problem with VS Express, I wound up having to open up the the .vcxproj file (which is just XML), and remove the offending < ClInclude Include="FILEPATHANDNAME" > tags.

OK, I have no idea how I did it but I'm still going to try to write what I did.

  1. Save all and Close solution
  2. Open the .vcxproj file (not .sln)
  3. Build -> Clean [Project Name]
  4. Save all and Close
  5. Open the .sln file again.
  6. Build -> Project Only -> Clean Only [Project Name]
  7. Build -> Project Only -> Build Only [Project Name]

That's exactly what I did and worked for me. I think the main thing to do is clean, save, close, open, build, but I'm not sure.

In Solution Explorer you can select/deselect option "Show All Files". Try both options and make sure excluded file is not included in project for both of them.

That's what I had: I used "Show All Files" option (so you can see all the files in project directories). I excluded one of my .cpp files from project. However, it behaved as this file is in project.

That's how I managed to fix it: I switched "Show All Files" off and saw this file still belongs to project! So I excluded this file once again.

As I see, that's a known issue.

This worked for me, hope it will be useful for someone else.

Many of the solutions here will not work

Fullproof method:

  1. Open the vxproj file that is giving you trouble in a text editor.
  2. remove all references to the file it cannot find.

Try to verbose builder output to see exact steps of what's going on. I suppose, you use Visual Studio, right?

  1. Go to menu "Tools -> Options"
  2. In options dialog, select "Projects and Solutions -> Build and Run"
  3. Change current mode of "MSBuild project build output verbosity" from "Minimal" to something like "Diagnostics" or "Detailed".
  4. Rebuild your project and investigate Output windows

Builder dump should shed more light on your current settings (I suspect you have more references to that file than you expect)