“Error C1083: can 't open source file”根本不应该查找文件

时间:2022-05-17 20:53:08

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)

我尝试#包含一个cpp文件和一些函数,这样我可以在以后的其他项目中使用这个cpp文件。它给了我一个“.obj中已经定义的”错误,从那以后。cpp文件就像与我的项目绑定在一起。(我知道这不是问题的答案,这里的答案帮助我解决了已经定义好的问题)

If I exclude the .cpp file from the project, remove it from the directory and remove the #include line 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 reset the project and recompile so that the program doesn't look for it? I already tried Rebuild and Clear -> Build Project

它根本不应该去找std.cpp,我把它移走了!有没有一种方法,我可以重置项目重新编译,这样程序就不会去找它?我已经尝试了重新构建和清除——>构建项目

12 个解决方案

#1


9  

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 ="FILEPATHANDNAME" >标记。

#2


6  

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. 保存所有和关闭的解决方案
  3. Open the .vcxproj file (not .sln)
  4. 打开.vcxproj文件(不是.sln)
  5. Build -> Clean [Project Name]
  6. Build -> Clean[项目名称]
  7. Save all and Close
  8. 保存并关闭
  9. Open the .sln file again.
  10. 再次打开.sln文件。
  11. Build -> Project Only -> Clean Only [Project Name]
  12. 只建设>项目-只清洁>[项目名称]
  13. Build -> Project Only -> Build Only [Project Name]
  14. 只建设>项目-只建设>[项目名称]

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.

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

#3


6  

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.

这就是我修复它的方法:我切换了“显示所有文件”,看到这个文件仍然属于project!所以我再次排除了这个文件。

As I see, that's a known issue.

在我看来,这是一个众所周知的问题。

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

这对我有用,希望对别人有用。

#4


3  

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,您应该会看到 中的违规文件。仅仅删除这些行。

#5


2  

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. 进入菜单“工具->选项”
  3. In options dialog, select "Projects and Solutions -> Build and Run"
  4. 在选项对话框中,选择“项目和解决方案—>构建和运行”
  5. Change current mode of "MSBuild project build output verbosity" from "Minimal" to something like "Diagnostics" or "Detailed".
  6. 将“MSBuild项目构建输出冗余”的当前模式从“最小”更改为“诊断”或“详细”。
  7. Rebuild your project and investigate Output windows
  8. 重新构建项目并研究输出窗口

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

构建器转储应该更清楚地显示当前设置(我怀疑您对该文件的引用比您预期的要多)

#6


2  

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: drive的文件夹时,这个问题就消失了。

#7


2  

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,源文件,选择文件,首先排除项目,然后重新添加到项目中,并重新构建它所生活的解决方案。它仍然在我的源文件下显示为旧文件名称。

#8


2  

Many of the solutions here will not work

这里的许多解决方案都行不通。

Fullproof method:

Fullproof方法:

  1. Open the vxproj file that is giving you trouble in a text editor.
  2. 打开在文本编辑器中给您带来麻烦的vxproj文件。
  3. remove all references to the file it cannot find.
  4. 删除它找不到的文件的所有引用。

#9


1  

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

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

#10


1  

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工作得很好。在使用项目>属性>使它们看起来相同之后,没有任何工作。我打开了.vcxproj文件,并将工作版本的内容复制到我的非工作版本中。我注意到这两个文件有不同的长度。非工作版本长了大约20行。我刚刚将RootNameSpace改成了非工作版本的名称。我保存了不工作的文件,立即!它工作。

#11


0  

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

这对我有帮助。综上所述,我的项目路径很长,所以我将我的项目移到了更短的地方,也就是D:\my_project,所有的事情都在眨眼之间就完成了。

#12


0  

For people having problem related to "error C1083: Cannot open source file":

对于“error C1083: can ' t open source file”有问题的人:

Error is caused by settings in *.vcxproj file. Probably you deleted/moved source file by file explorer, not by Visual Studio's "Solution Explorer". Thus, your *.vcxproj file is corrupted. Fix is to manually correct settings in *.vcxproj file.

错误是由*中的设置引起的。vcxproj文件。您可能是通过文件资源管理器删除/移动源文件,而不是通过Visual Studio的“解决方案资源管理器”。因此,你的*。vcxproj文件损坏。修正是手动修正*中的设置。vcxproj文件。

How Visual Studio settings files work

Visual Studio如何设置文件

Visual Studio saves solution's info into file. This file is usually in project's solution directory, has extension .sln and base name is same as name of solution, f.ex.:

Visual Studio将解决方案的信息保存到文件中。此文件通常在项目的解决方案目录中,扩展名为.sln,基本名与解决方案的名称f.ex相同。

NameOfSolution.sln

NameOfSolution.sln

Similarly, project's info is saved into one file (each project has its own file). Base name of this file is name of project, extension is .vcxproj, and usually is located in subdirectory named as your project, f.ex.:

类似地,项目信息被保存到一个文件中(每个项目都有自己的文件)。该文件的基本名称是项目名称,扩展名是.vcxproj,通常位于名为“您的项目”的子目录中。

NameOf1stProject/NameOf1stProject.vcxproj

NameOf1stProject / NameOf1stProject.vcxproj

NameOf2ndProject/NameOf2ndProject.vcxproj

NameOf2ndProject / NameOf2ndProject.vcxproj

Both *.sln and *.vcxproj files are textual files. You can open them by using Notepad.

*。sln和*。vcxproj文件是文本文件。您可以使用记事本打开它们。

How to fix problem

如何解决问题

  1. Find *.vcxproj file responsible for your project.

    找到*。vcxproj文件负责您的项目。

    If you don't know where it is, open in Notepad the *.sln file of your solution. Search for name of your solution. You will find line like:

    如果你不知道它在哪里,在记事本中打开。解决方案的sln文件。搜索解决方案的名称。你会发现这样的句子:

    Project("{9AA9CEB8-8B4A-11D0-8D22-00B0C01AA943}") = "NameOf1stProject", "NameOf1stProject\NameOf1stProject.vcxproj", "{A8735D0A-25ED-4285-AB8F-AF578D8DB960}"
    

    Value under "NameOf1stProject\NameOf1stProject.vcxproj" is location of *.vcxproj file of your project.

    在“NameOf1stProject \ NameOf1stProject价值。vcxproj"是*的位置。项目的vcxproj文件。

  2. Open found *.vcxproj file by text editor (f.ex. Notepad).

    打开发现*。文本编辑器(f.ex)生成的vcxproj文件。记事本)。

  3. Search for line on which is filename you are struggling with.

    搜索正在与之斗争的文件名的行。

    Example: if you are looking for "RemovedFile.cpp", then you should find line:

    示例:如果您正在查找“RemovedFile”。那么你应该找一行:

    <ClCompile Include="RemovedFile.cpp" />
    
  4. Delete that line.

    删除这条线。

  5. If you have opened Visual Studio, it asks you if it should refresh solution - select yes. If it is not opened - just start using it.

    如果你打开了Visual Studio,它会问你是否需要刷新解决方案——选择yes。如果没有打开,就开始使用它。

  6. In case of any problems, try to rebuild solution (top banner -> Build -> Rebuild Solution)

    如果有任何问题,尝试重新构建解决方案(顶部横幅->构建->重建解决方案)

In my cases, it worked. 30 mins of trying to fix, <1 minute of fixing.

在我的案例中,它起作用了。30分钟尝试修复,<1分钟修复。

#1


9  

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 ="FILEPATHANDNAME" >标记。

#2


6  

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. 保存所有和关闭的解决方案
  3. Open the .vcxproj file (not .sln)
  4. 打开.vcxproj文件(不是.sln)
  5. Build -> Clean [Project Name]
  6. Build -> Clean[项目名称]
  7. Save all and Close
  8. 保存并关闭
  9. Open the .sln file again.
  10. 再次打开.sln文件。
  11. Build -> Project Only -> Clean Only [Project Name]
  12. 只建设>项目-只清洁>[项目名称]
  13. Build -> Project Only -> Build Only [Project Name]
  14. 只建设>项目-只建设>[项目名称]

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.

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

#3


6  

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.

这就是我修复它的方法:我切换了“显示所有文件”,看到这个文件仍然属于project!所以我再次排除了这个文件。

As I see, that's a known issue.

在我看来,这是一个众所周知的问题。

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

这对我有用,希望对别人有用。

#4


3  

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,您应该会看到 中的违规文件。仅仅删除这些行。

#5


2  

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. 进入菜单“工具->选项”
  3. In options dialog, select "Projects and Solutions -> Build and Run"
  4. 在选项对话框中,选择“项目和解决方案—>构建和运行”
  5. Change current mode of "MSBuild project build output verbosity" from "Minimal" to something like "Diagnostics" or "Detailed".
  6. 将“MSBuild项目构建输出冗余”的当前模式从“最小”更改为“诊断”或“详细”。
  7. Rebuild your project and investigate Output windows
  8. 重新构建项目并研究输出窗口

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

构建器转储应该更清楚地显示当前设置(我怀疑您对该文件的引用比您预期的要多)

#6


2  

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: drive的文件夹时,这个问题就消失了。

#7


2  

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,源文件,选择文件,首先排除项目,然后重新添加到项目中,并重新构建它所生活的解决方案。它仍然在我的源文件下显示为旧文件名称。

#8


2  

Many of the solutions here will not work

这里的许多解决方案都行不通。

Fullproof method:

Fullproof方法:

  1. Open the vxproj file that is giving you trouble in a text editor.
  2. 打开在文本编辑器中给您带来麻烦的vxproj文件。
  3. remove all references to the file it cannot find.
  4. 删除它找不到的文件的所有引用。

#9


1  

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

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

#10


1  

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工作得很好。在使用项目>属性>使它们看起来相同之后,没有任何工作。我打开了.vcxproj文件,并将工作版本的内容复制到我的非工作版本中。我注意到这两个文件有不同的长度。非工作版本长了大约20行。我刚刚将RootNameSpace改成了非工作版本的名称。我保存了不工作的文件,立即!它工作。

#11


0  

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

这对我有帮助。综上所述,我的项目路径很长,所以我将我的项目移到了更短的地方,也就是D:\my_project,所有的事情都在眨眼之间就完成了。

#12


0  

For people having problem related to "error C1083: Cannot open source file":

对于“error C1083: can ' t open source file”有问题的人:

Error is caused by settings in *.vcxproj file. Probably you deleted/moved source file by file explorer, not by Visual Studio's "Solution Explorer". Thus, your *.vcxproj file is corrupted. Fix is to manually correct settings in *.vcxproj file.

错误是由*中的设置引起的。vcxproj文件。您可能是通过文件资源管理器删除/移动源文件,而不是通过Visual Studio的“解决方案资源管理器”。因此,你的*。vcxproj文件损坏。修正是手动修正*中的设置。vcxproj文件。

How Visual Studio settings files work

Visual Studio如何设置文件

Visual Studio saves solution's info into file. This file is usually in project's solution directory, has extension .sln and base name is same as name of solution, f.ex.:

Visual Studio将解决方案的信息保存到文件中。此文件通常在项目的解决方案目录中,扩展名为.sln,基本名与解决方案的名称f.ex相同。

NameOfSolution.sln

NameOfSolution.sln

Similarly, project's info is saved into one file (each project has its own file). Base name of this file is name of project, extension is .vcxproj, and usually is located in subdirectory named as your project, f.ex.:

类似地,项目信息被保存到一个文件中(每个项目都有自己的文件)。该文件的基本名称是项目名称,扩展名是.vcxproj,通常位于名为“您的项目”的子目录中。

NameOf1stProject/NameOf1stProject.vcxproj

NameOf1stProject / NameOf1stProject.vcxproj

NameOf2ndProject/NameOf2ndProject.vcxproj

NameOf2ndProject / NameOf2ndProject.vcxproj

Both *.sln and *.vcxproj files are textual files. You can open them by using Notepad.

*。sln和*。vcxproj文件是文本文件。您可以使用记事本打开它们。

How to fix problem

如何解决问题

  1. Find *.vcxproj file responsible for your project.

    找到*。vcxproj文件负责您的项目。

    If you don't know where it is, open in Notepad the *.sln file of your solution. Search for name of your solution. You will find line like:

    如果你不知道它在哪里,在记事本中打开。解决方案的sln文件。搜索解决方案的名称。你会发现这样的句子:

    Project("{9AA9CEB8-8B4A-11D0-8D22-00B0C01AA943}") = "NameOf1stProject", "NameOf1stProject\NameOf1stProject.vcxproj", "{A8735D0A-25ED-4285-AB8F-AF578D8DB960}"
    

    Value under "NameOf1stProject\NameOf1stProject.vcxproj" is location of *.vcxproj file of your project.

    在“NameOf1stProject \ NameOf1stProject价值。vcxproj"是*的位置。项目的vcxproj文件。

  2. Open found *.vcxproj file by text editor (f.ex. Notepad).

    打开发现*。文本编辑器(f.ex)生成的vcxproj文件。记事本)。

  3. Search for line on which is filename you are struggling with.

    搜索正在与之斗争的文件名的行。

    Example: if you are looking for "RemovedFile.cpp", then you should find line:

    示例:如果您正在查找“RemovedFile”。那么你应该找一行:

    <ClCompile Include="RemovedFile.cpp" />
    
  4. Delete that line.

    删除这条线。

  5. If you have opened Visual Studio, it asks you if it should refresh solution - select yes. If it is not opened - just start using it.

    如果你打开了Visual Studio,它会问你是否需要刷新解决方案——选择yes。如果没有打开,就开始使用它。

  6. In case of any problems, try to rebuild solution (top banner -> Build -> Rebuild Solution)

    如果有任何问题,尝试重新构建解决方案(顶部横幅->构建->重建解决方案)

In my cases, it worked. 30 mins of trying to fix, <1 minute of fixing.

在我的案例中,它起作用了。30分钟尝试修复,<1分钟修复。