C++ “错误 C1083:无法打开源文件”根本不应该查找文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16422883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:20:32  来源:igfitidea点击:

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

c++

提问by Bonnev

I was trying to #includea cppfile 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 herehelped me with the already defined)

我正在尝试使用某些功能创建#include一个cpp文件,以便稍后可以在其他项目中使用该 cpp 文件。它给了我一个“已经在 .obj 中定义”的错误,从那时起 .cpp 文件就像绑定了我的项目。(我明白那不是这样,这里的答案帮助我解决了已经定义的问题

If I excludethe .cpp file from the project, removeit from the directory andremove the #includeline it still looks for it:

如果我从项目中排除.cpp 文件,请将其从目录中删除删除#include它仍在查找的行:

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 resetthe project and recompileso that the program doesn't look for it? I already tried Rebuildand Clear -> Build Project

它根本不应该寻找 std.cpp,我删除了它!那么有没有办法可以重置项目并重新编译,以便程序不查找它?我已经尝试过重建清除 - > 构建项目

采纳答案by Bonnev

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

好吧,我不知道我是怎么做到的,但我仍然会尝试写我所做的。

  1. Save alland Close solution
  2. Open the .vcxprojfile (not .sln)
  3. Build-> Clean [Project Name]
  4. Save alland Close
  5. Open the .slnfile again.
  6. Build-> Project Only-> Clean Only [Project Name]
  7. Build-> Project Only-> Build Only [Project Name]
  1. 全部保存关闭解决方案
  2. 打开.vcxproj文件(不是 .sln)
  3. 构建->清理 [项目名称]
  4. 全部保存关闭
  5. 再次打开.sln文件。
  6. 构建->仅项目->仅清理 [项目名称]
  7. 构建->仅项目->仅构建 [项目名称]

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.

这正是我所做的和为我工作的。我认为要做的主要事情是清理、保存、关闭、打开、构建,但我不确定。

回答by AaronF

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.

当我在 VS Express 中遇到类似问题时,我不得不打开 .vcxproj 文件(它只是 XML),并删除有问题的 < ClInclude Include="FILEPATHANDNAME" > 标签。

回答by user3045699

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.

这就是我所拥有的:我使用了“显示所有文件”选项(因此您可以看到项目目录中的所有文件)。我从项目中排除了我的 .cpp 文件之一。但是,它的行为就像此文件在项目中一样。

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.

这对我有用,希望对其他人有用。

回答by randyrand

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.
  1. 在文本编辑器中打开给您带来麻烦的 vxproj 文件。
  2. 删除对它找不到的文件的所有引用。

回答by Yury Schkatula

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

尝试详细构建器输出以查看正在发生的确切步骤。我想,您使用 Visual Studio,对吗?

  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
  1. 转到菜单“工具->选项”
  2. 在选项对话框中,选择“项目和解决方案 -> 构建和运行”
  3. 将“MSBuild project build output verbosity”的当前模式从“Minimal”更改为“Diagnostics”或“Detailed”。
  4. 重建您的项目并调查输出窗口

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

Builder dump 应该更清楚地说明您当前的设置(我怀疑您对该文件的引用比您预期的要多)

回答by Shital Shah

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.

这发生在我身上,因为我从 IDE 内部重命名了文件夹。上述解决方案均无效。解决此问题的唯一方法是在记事本中打开 vcproj,您应该会在<ItemGroup>. 只需删除这些行。

回答by A.D.

Or sometimes, like in my case, the issue is simply in the naming of the folders in the location. I had a very long path with folders that I like to name with special characters so they show up at the top and it's easy to access them. As soon as I put my solution in a folder just in D: drive, the issue was gone.

或者有时,就像在我的情况下,问题仅仅在于该位置文件夹的命名。我有一个很长的路径,我喜欢用特殊字符命名文件夹,以便它们显示在顶部并且很容易访问它们。一旦我将我的解决方案放在 D: 驱动器中的文件夹中,问题就消失了。

回答by Michele

When I renamed a file, I found I had to go to SolutionExplorer, Source File, select the file, first exclude from Project, then re-add it to project, and rebuild the solution it lives in. It was still showing up as the old file name under Source Files for me.

当我重命名一个文件时,我发现我必须转到 SolutionExplorer,源文件,选择该文件,首先从 Project 中排除,然后将其重新添加到项目中,并重建它所在的解决方案。它仍然显示为我的源文件下的旧文件名。

回答by Patrizio Bertoni

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

我从 Project 中删除了这些源并重新添加了它们。不知何故,在匆忙的项目重构之后,引用被搞砸了。

回答by Brian S. Penn

I had the same problem, but I had another .sln worked fine. After tooling around with the Project->Properties-> to make them look identical, nothing worked. I opened both .vcxproj files and copied the contents of the working version into my non-working version. (I noticed that the two files had different lengths. The non-working version was longer by about 20 lines.) I just changed the RootNameSpace to the non-working version's name. I saved the non-working file and presto! It worked.

我有同样的问题,但我有另一个 .sln 工作正常。在使用 Project->Properties-> 使它们看起来相同后,没有任何效果。我打开了两个 .vcxproj 文件并将工作版本的内容复制到我的非工作版本中。(我注意到这两个文件的长度不同。非工作版本长了大约 20 行。)我只是将 RootNameSpace 更改为非工作版本的名称。我保存了非工作文件并快速!有效。