“Error C1083: Cannot open source file” Shouldn'

2020-07-02 09:26发布

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

Diagnostic:

Outputs for D:\MY DOCUMENTS\C#\PROJECT\D3DTESTC++\COWS AND BULLS\CBMAIN.CPP|D:\MY DOCUMENTS\C#\PROJECT\D3DTESTC++\COWS AND BULLS\STD.CPP: (TaskId:15)

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

标签: c++
13条回答
Juvenile、少年°
2楼-- · 2020-07-02 09:48

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)

查看更多
贼婆χ
3楼-- · 2020-07-02 09:50

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.

查看更多
戒情不戒烟
4楼-- · 2020-07-02 09:53

This happened to me because I renamed folder from inside the IDE. None of the above solutions worked. The only way to fix this is by opening vcproj in notepad and you should see the offending files in the <ItemGroup>. Just delete those lines.

查看更多
ら.Afraid
5楼-- · 2020-07-02 09:54

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.
查看更多
仙女界的扛把子
6楼-- · 2020-07-02 09:55

I removed those sources from Project and re-added them. Somehow, references were messed up after a hurry project refactoring.

查看更多
\"骚年 ilove
7楼-- · 2020-07-02 09:56

This helped in my case. To sum it up, my path to the project was too long, so I moved my project to something shorter i.e. D:\my_project and everything worked in a blink of an eye.

查看更多
登录 后发表回答