17

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

Community
  • 1
  • 1
Bonnev
  • 947
  • 2
  • 9
  • 29
  • Have you tried the "Clean-up solution" in the Generate menu ? – JBL May 07 '13 at 15:28
  • I can't find any Generate menu, I'm using Visual C++ Express 2010. There is a **Clean Solution** in the **Build** menu and I've tried it, doesn't work. – Bonnev May 07 '13 at 15:35
  • Are you sure you haven't deleted the file itself? To me the error message is saying that the file is in the project but not on the disk. – john May 07 '13 at 15:42
  • I'm sure I HAVE deleted the file, from the project and from the directory, the file is now history to everyone except the project and I'm wondering why.. – Bonnev May 07 '13 at 15:45
  • 1
    Have you **excluded** the file from the project or have you **deleted** the file from the project? I seem to remember than VC++ 2010 gives you both options. I would recommend delete especially since you have also deleted the file itself. – john May 07 '13 at 15:53
  • It's excluded from the project. – Bonnev May 07 '13 at 16:01
  • Well I would try deleting it. Select the file in the project explorer and press delete. – john May 07 '13 at 16:03
  • @john It's not there, there's no sign of it anywhere. – Bonnev May 07 '13 at 16:47
  • @Bonnev There's a button in the solution explorer 'Show All Files', make sure that is selected. An excluded file should be visible (otherwise how would you ever include it again). If all else fails just start again and recreate the project. – john May 07 '13 at 18:25
  • When selected it shows all the files currently in the directory. No, I'm sure that it's gonna work fine if I make a new project and copy the source file or so, I just wanted to figure a way around it, if it happens again I'll be forced to stop my work and make a new project and delete the old one... I wanna find what's causing it – Bonnev May 07 '13 at 20:45
  • For me, it was showing up under solution explorer under the old name still (source files), so I removed it and added the new file name, cleaned and built, and that worked. – Michele Feb 08 '17 at 13:10

17 Answers17

17

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.

AaronF
  • 2,841
  • 3
  • 22
  • 32
14

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.
randyrand
  • 433
  • 1
  • 4
  • 9
  • 1
    This one actually worked for me. Accepted answer didn't. – Mert Apr 19 '20 at 12:59
  • 1
    The same thing happened to me - The accepted answer didn't work, but I opened the vxproj file and deleted the references for the file, and the project compiled well. I'm using VS2022 by the way. – Jonathan Feb 13 '22 at 06:59
12

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.

Bonnev
  • 947
  • 2
  • 9
  • 29
  • 1
    I renamed one of source files and this problem occured. Your solution didn't seem promising, but it worked for me. Thanks! – BartekM Sep 20 '16 at 22:00
9

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.

user3045699
  • 91
  • 1
  • 1
3

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)

Yury Schkatula
  • 5,291
  • 2
  • 18
  • 42
  • I already have the diagnostic option on, I still can't understand where it comes from. – Bonnev May 07 '13 at 21:21
  • That way, I'd recommend doing full-text search in the solution folder (including all subfolders) for "std" string, as a last resort. This may give you some clues where that name referenced actually. – Yury Schkatula May 07 '13 at 23:57
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.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Shital Shah
  • 63,284
  • 17
  • 238
  • 185
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.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Pixie
  • 311
  • 2
  • 14
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.

Yousuf Azad
  • 414
  • 1
  • 7
  • 17
Michele
  • 3,617
  • 12
  • 47
  • 81
2

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 actually put this answer here for myself. This keeps happening with the main error being "IntelliSense: cannot open source file" Arrrggghhh! The problem is that it is so infrequent, that I forget to search for the c1083 error..it's buried down in the compiler messages. Beware!! – Brian S. Penn Mar 15 '18 at 14:34
  • Also, I was trying to upgrade my MSVS C 2010 code to incorporate FLTK in running in MSVS 2015. This only seems to work if I create a new project in MSVS2015 then copy the old code over to the new project. – Brian S. Penn Jun 06 '20 at 14:08
1

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

Patrizio Bertoni
  • 2,582
  • 31
  • 43
1

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.

krizajb
  • 1,715
  • 3
  • 30
  • 43
  • My file was in GDrive and it added my email to the drive name (I have multiple) GDrives. Once everything was in DropBox, the error went away. I'd initially compiled on c/ drive then moved the folder to GDrive and had not changed the .h or .cpp files since. When I went to add a .cpp, there was the error. – forest.peterson Dec 13 '19 at 18:21
1

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

  1. 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.

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

  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:

    <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.

  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.

apanas
  • 11
  • 1
1

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.

Fred
  • 1,054
  • 1
  • 12
  • 32
1

I had used the <ClCompile> instead of the <ClInclude> which should be used for header files.

Silly mistake while copy pasting things.

Saurabh
  • 95
  • 2
  • 8
0

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

Fei Fang
  • 1
  • 1
0

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.

0

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.

enter image description here

The remove option comes after right clicking on the file names.

surajj4837
  • 49
  • 1
  • 10