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

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

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.

Many of the solutions here will not work
Fullproof method:
Open the vxproj file that is giving you trouble in a text editor.
remove all references to the file it cannot find.

OK, I have no idea how I did it but I'm still going to try to write what I did.
Save all and Close solution
Open the .vcxproj file (not .sln)
Build -> Clean [Project Name]
Save all and Close
Open the .sln file again.
Build -> Project Only -> Clean Only [Project Name]
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.

Try to verbose builder output to see exact steps of what's going on. I suppose, you use Visual Studio, right?
Go to menu "Tools -> Options"
In options dialog, select "Projects and Solutions -> Build and Run"
Change current mode of "MSBuild project build output verbosity" from "Minimal" to something like "Diagnostics" or "Detailed".
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)

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.

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.

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.

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.

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

For people having problem related to "error C1083: Cannot 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.
How Visual Studio settings files work
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.:
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.:
NameOf1stProject/NameOf1stProject.vcxproj
NameOf2ndProject/NameOf2ndProject.vcxproj
Both *.sln and *.vcxproj files are textual files. You can open them by using Notepad.
How to fix problem
Find *.vcxproj file responsible for your project.
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:
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.
Open found *.vcxproj file by text editor (f.ex. Notepad).
Search for line on which is filename you are struggling with.
Example: if you are looking for "RemovedFile.cpp", then you should find line:
<ClCompile Include="RemovedFile.cpp" />
Delete that line.
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.
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.

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.

I had this same problem, but for me the issues was that I was using Bash on Windows (WSL) to clone the repository and then using VS to compile.
Once I deleted my clone and used Windows command line (cmd.exe) to clone the repo then the error 1083 went away.

This is caused by not removing/deleting the file properly. Go to Solution Explorer, select your solution, at the left corner, activate the icon: show all files.
(if you already removed the problem file, restore it from recycle bin)
Select the problem file, do remove and delete from within Solution Explorer and you should not have this problem. And remember to do it the proper way from now on.
This is on MS 2010

If you have that file in your project directory but you still got the error, on your IDE go to Solution explorer--> Remove that file-->then open the project directory on your file explorer-->Select that file and drop it on a specific location in IDE solution explorer. I fixed it this way. I use the Windows platform.

I got this error when I got a code from my peer and I tried directly running it on my system. Ideally to avoid such errors, I should have just copied the source and header files and should have created the VS solution of my own.
To resolve the errors I removed the files from the Solution Explorer and added them again. Following image shows the Solution Explorer window.
The remove option comes after right clicking on the file names.

Related

How to properly delete projects in PlatformIO?

I use PlatformIO with Visual Studio Code on Windows 10.
Now whenever I:
create a Project with a name X
close Visual Studio Code
delete the Project folder X
open Visual Studio Code
create a new Project with the same name X
I get an empty project with a main.cpp file as expected, but the IDE shows an error for the line:
#include <Arduino.h>
The Error says: "Include Error recognised. Update your includePath." (Translated)
However, if I try to build, it compiles just fine. Even uploading and running works.
This include error appears not only with Arduino.h but with all includes, even if the file is in the exact same location. And it appears in other files than just main.cpp as well.
Can you tell me why this happens? How can I reuse the project names of deleted projects? Or If I should not delete projects like this (delete the project folder), how else would I delete a project?
I tried this with multiple project names and different boards, always with the same result.
Things I tried so far:
I found a Folder .cache in the PIO directory. But unfortunately renaming it (after step 3) did not help: after restarting PIO it recreated the folder as expected but the error message is still here.
In the same location there is a file homestate.json that among other things contains the path to recently opened projects. I removed those entries without luck.
I am just starting out with VSCoode and PlatformIO so i can't tell you why all of what you are seeing is happening is happening.
I use VSCode v1.63.0 on Windows 10.
If you want to delete the old project name, reuse it or not, you can bring up the Command Palette under the View menu (Shift-Control-P for me) and search for Workspace: Remove Folder from Workspace...., it will only be listed if you have projects in the workspace. A list of projects will be displayed, selected which one to delete and click on it. There will not be a confirmation prompt.

How to know which project a source file belongs to?

I am using Visual Studio 2008 Version 9.0.30729.1 SP. I am working on a "solution" of 27 projects. Each project contains several source files - *.cpp files and header files *.h.
Now, using the find function (control + f) I have managed to open a source file A.cpp. However, I do not know which project it belongs to. I have searched the Internet without success. I am sure there must be a way, sorry for being a noob.
In Eclipse there is a way of doing this, is there a way to do this in VS as well?
Press Ctrl+; and start typing the name of the file. That will limit the solution explorer view to just the named file. You can open the file from there, too. That's typically easier than using File/Open, provided that the file is in your solution.
Still a few more keystrokes once you've opened a file using a text search , but I think it is the simplest way.
I am writing this answer courtesy HansPassant.
Tools > Options > Projects and Solutions > General > tick the "Track active item in Solution Explorer" option. This will highlight the source file in the project in the solution explorer window. Just as it does in eclipse.

The desired name for <file> is invalid - visual studio 2015

This is pretty crazy, I am only adding an existing .h file to VS2015 C++ project but it would complain:
The desired name for c:\code\usbview\USBdevices.h is invalid
I was able to add this file to project when it had its own .sln file. However, I created a new empty .sln file and wanted to add this and other project and that's how this issue kicked in. It wouldn't add this project to new solution giving a similar weird error about the files I added.
I then add the base project to that solution file and tried to add this .h and .cpp files there but it adds the .cpp but gives this error for .h file.
This is very weird, I changed the files names but the same error.
The link in the comment section by BlackDwarf fixed the problem even though that was was for C# but applies.
I didn't have USERPROFILE environment variable so I created it and set it to c:\Users\my.name and now I can add the file
I had the same problem and it was because of merge errors in the file ProjectName.vcxproj.filters.
The answers here led me to check my vcxproj when I experienced the OP's problem.
It turns out I had two filters with the same name in my Project.vcxproj.filters, something like
<Project>
<Common>
...
...
<Stuff>
<Common>
And I was trying to add files to the second Common.
To fix it, I had to ..
edit the vcxproj manually in {favoured text editor} and remove the second filter I'd added with a duplicate name.
Unload/Reload the project from the solution in VS(2017), and add a filter with a unique name. All good - I can add files to my new filter.
I use VS 2013 Express and had the same error.
Solved by removing VCTargetsPath environment variable, I added it some time ago, don't remember why :)
I had the same issue, but the solution had nothing to do with "Environment Variables" for me. What I did: Close Visual Studio 2017. Reopen my project. Suddenly I had two copies of the "Helper.cpp" and "Helper.h" that I was trying to add already as part of the solution files. Clicking on each I saw that one of the files was invalid, probably because I had deleted that version of the file in that file location. I deleted the invalid files, checked to make sure that the files had the correct code I wanted in them, built the solution and everything ran fine.
Not sure why closing and reopening VS fixed the problem, but glad it did.
If the environment variable route doesn't work for you, check the integrity of your project file next.
I had this problem in 2017, and it was due to a double entry in the vcxproj from a manual editing error. Our vcxproj file had the following in it:
<ClInclude Include="XXXX.h" />
<ClCompile Include="XXXX.h" />
In 2017 we got exactly the error you described when trying to add an existing file, a slightly different one when adding new, and strange crashes elsewhere. Opening the solution in 2015 logged the exact problem and failed to load the project. We removed the double entry and all the mysterious problems vanished.

Cant open html resource file using ifstream::open - Visual Studio 2013

I am working on a project which requires me to open an HTML file and use its contents. I added it to Resource files but when I try to open it lie this:
std::ifstream templateFile;
templateFile.open("filename.html", std::ifstream::in);
The operation fails. I checked it by using templateFile.fail().
The above operation works when I provide the full path. The file lies in the project folder along with other files. I tried setting build action to content but still it doesnt work. Please Help.
Output directory, where your executable is compiled and put into differs from the source directory, where you create all your .cpp/.hpp files (I assume there is filename.html file). Local path filename.html is supposed to be local for your executable file, not the source file.
Read more about changing the output directory here: https://msdn.microsoft.com/en-us/library/ms165410.aspx
Under Configuration Properties / Debugging, see what your Working Directory is using the macros dialog box. Move your file into this folder.
Click the button shown in the figure. There, click either Edit or Browse. Browse will take you to the working directory. Edit will expose the link to open the macros box

What are C2471,C1083 errors related to a VC2008 project and how to correct them

I had a VC2008 project very complicated.Inorder to understand it's inner workings I tried to simplify it and now I am getting 289 errors of the following type for most of the files:
Error 5 error C2471: cannot update program database 'c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\debug\vc90.pdb' c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\mediainfo\file__analyze_buffer_minimizesize.cpp 1 CLI
Error 6 fatal error C1083: Cannot open program database file: 'c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\debug\vc90.pdb': No such file or directory c:\users\ryan\documents\visual studio 2008\projects\vc\myinfo\cli\mediainfo\file__analyze_buffer_minimizesize.cpp 1 CLI
My system : win7/VS2008
Solution 1: Locate *.vcxproj file in your solution, open in a text editor and search for 'DebugInformationFormat' and set it to 'OldStyle'.  Reload your project and build. If you have multiple projects in your solution, this change needed for all the *.vcxproj files.
< DebugInformationFormat>OldStyle< /DebugInformationFormat>
Solution 2: From Visual Studio, on every project in your solution right click and open Properties. Expand 'Configuration Properties' > 'C/C++' > 'General'. Change the 'Debug Information Format' to 'C7 compatible (/Z7)'. Then build your solution.
This worked for me. (YMMV = Your mileage may vary:)
I've seen the same behaviour when converting a VS2003.Net solution to run on later IDEs. My guess is that your solution contains multiple projects which point to the same intermediate directory. In VS2005 and later, projects that don't depend on each other can be built in parallel so that if the same working dir is used, you can get file conflicts like this.
Check this as follows. In Solution Explorer, right click on one of the failing projects and select Properties. In Configuration Properties -> General section, make sure that every project has a different 'Intermediate Directory'. Try your build again using 'Rebuild Solution' to clean everything out.
Most of the times when I get "C2471: cannot update program database" it's because the PDB file is locked for some reason. Usually in my case that turns out to be because I have the program running in some other window, which loads the PDB file in to memory.
When that's not the reason, I find doing a rebuild-all magically fixes the problem.
I've encountered the same type of error myself with no end of frustration.
I finally fixed it by applying the Microsoft hot fix found in this knowledge base article: http://archive.msdn.microsoft.com/KB946040
This worked for me.
Kill mspdbsrv.exe and reload Visual C++
MSDN
You can delete the *.obj file and rebuild the solution again, This problem might solve. Below link might be helpful for you-
https://social.msdn.microsoft.com/Forums/vstudio/en-US/0ceac3c6-62f6-4fdf-82e1-d41e1b4fcd20/vs2008-c2471-cannot-update-program-database?forum=vclanguage