Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio warning about copies of files with different contents

When I go to debug my C++ project in Visual Studio, up pops a little warning dialogue box that tells me:

A copy of datum.h was found in
c:/users/brad/desktop/source/binary/datum.h, but the current
source code is different from the version built into
c:/users/brad/desktop/source/binary/datum.h.

I'm having trouble understanding what this is even trying to tell me, let alone how to fix it. At first I thought it might be complaining that I'd accidentally duplicated a file in the directory, which I checked, and found nothing of the sort, which leaves me pretty stumped. I also tried excluding the file from the solution and adding it again, which didn't fix the problem either.

The warning doesn't appear to actually hinder the development of my project, but I suppose warnings exist for a reason, so if anyone knows what's gone wrong, any advice would be greatly appreciated. To my knowledge, I didn't change anything to cause the message to appear, it just popped up one time I went to debug the solution and has kept on appearing ever since.

Also, more copies of the same warning have started popping up, pertaining to other header files in my solution (I haven't recieved any about .cpp files yet, but it could be a coincidence, because it's only been going on for about 20 minutes).

like image 701
brads3290 Avatar asked Apr 28 '15 08:04

brads3290


4 Answers

Try removing breakpoints from the file in question. This worked for me when it occurred with Visual Studio 2013 for a header file in debug build. Source: Release mode file sync issue - current source code different from the version built

Additional notes: Clean / Rebuild also works, but that is painful for regularly changing code. Enabling the break point after starting debugger merely delays the message.

like image 178
Greg Avatar answered Nov 18 '22 18:11

Greg


I solved it:

  1. Close the window of the .h file in Visual Studio if it's open.
  2. Close Visual Studio.
  3. CUT the .h file from its normal location and paste it into a temporary folder that VS doesn't know about.
  4. Restart VS and compile. It'll complain about the missing .h file. Good -- Make the bastard beg for it!
  5. Paste the .h file back into its original location.
  6. Compile. VS will gratefully accept the missing file. (Damn I hate Microsoft!)
like image 44
UserX Avatar answered Nov 18 '22 18:11

UserX


This occurs if you rename an implementation file (*.c, *.cpp, etc.) to a header file.

This is because the Item Type still remains as C/C++ Source File, making it get compiled as a separate translation unit rather than as an actual header, preventing Visual Studio from recognizing its inclusion as a header elsewhere.

It took me quite a while to figure this out.

To fix this:

  1. Right-click your header file in Solution Explorer and select Properties.

  2. Select All Configurations, All Platforms.

  3. Under General, change Item Type to C/C++ Header.

  4. Press OK.

  5. Force-recompile any file that #includes your header (or just Rebuild the solution).

like image 8
user541686 Avatar answered Nov 18 '22 18:11

user541686


The problem is that the debugger thinks that the checksum of the source file is different from what the compiler calculated and put in there. The debugger will then refuse to apply breakpoints in the files that mis-match, to prevent you from seeing data it can't guarantee is correct.

I have had this keep happening even after a clean rebuild. This is with VS 2015. My guess is perhaps the debugger and the compiler disagree on how to hash newlines or something like that? The fix is to turn off "require source files to exactly match the original version" in Debug -> Options -> Debugging -> General

like image 4
Jon Watte Avatar answered Nov 18 '22 18:11

Jon Watte