Is the project damaged?:. Cpp does not recompile automatically after editing the associated header file

For simplicity, I have a project whose classes / files can be divided into two groups B and C
C usually depends on ( #include ) some B
Say C1 , C2 , ... and C5 depend on B1 , nothing special here: -

B1.h

 class B1{/** some code */}; 

B1.cpp

 #include "B1.h" /** some code */ 

C1.h

 class C1{/** some code */}; 

C1.cpp

 #include "C1.h" #include "B1.h" /** some code */ 

C2.h

 class C2{/** some code */}; 

C2.cpp

 #include "C2.h" #include "B1.h" /** some code */ 

Problem

When I change B1.h and B1.h F5 , I should recompile both C1.cpp and C2.cpp .
But in my case this is not so: VS only C1.cpp recompiled.

I need to rebuild the entire project in order to indirectly force C2.cpp recompile, otherwise this error will occur: -

a copy of B1.h was found in d: ... \ B1.h, but the current source code is different from the version built into d: .... \ B1.h

Note. The two locations d:\...\B1.h are exactly the same.

After months of coding, this problem just happened to me yesterday. The problem occurs only for this specific file ( B1.h ), after an exhaustive search for errors.
Other Bi 's fine.

What i tried

(similar to the answers to this question )

  • Delete everything in the bin folder (both debug and release) - the #X folder (see below)
  • Clear the project and rebuild (this is just a one-time treatment.)
  • Refactoring (automatic renaming) B1 to another (also file name)
  • Delete the file, create a new B1.h file, then copy the source code from the old B1.h
  • Restart your computer several times.
  • Delete everything in the Template folder in Visual Studio ( %Temp% )
  • Delete all .suo , .user , .ncb , .sbr , .log , .sdf , .pdb associated with my project
  • Verify that the system time and time are consistent with C2.cpp date modified .
  • ( Change ). Make sure stdafx.h does not contain files that are part of my project, for example. B , C and others that include B or C (in) directly.
  • ( Change ). Make sure stdafx.h not #include -ed with any files, except for project settings.
    Thanks to Ari0nhh, user975989 and TripeHound.
  • ( Change ). Make sure that with a complete overhaul, C2.cpp really includes B1.h (look at the show include console).
  • ( Change ). Recovery VS2015 does not help.
  • ( Edit ) Removing most VS2015 extensions does not help.

Clue 1

If I change C2.cpp (for example, adding a space character), then save and build, C2.cpp will be attached to B1.h

Now, if I edit B1.h and press F5 , C2.cpp will now be automatically recompiled (correctly).
This is not a cure, because I also have many others besides C2 who want to associate with B1.h
... and this is very suspicious
... after I changed some project settings (not sure what), C2.cpp no longer connected.

Clue 2

Delete / recreate new B1.h file
This solution fixes the problem, but the effect will disappear if I restart the computer.

Question

  • How to fix the project in order to perform the automatic recompilation procedure again?

    More specifically, I am looking for some kind of " final clean / repair of this project ."
  • (secondary question) What is the cause of the problem?

It is difficult to determine the cause, so partial answers or uncertain assumptions are welcome.

Some progress

A day later, he finally recompiled C2.cpp correctly - even after restarting the computer.

I'm still not sure which of my actions it fixed.

However, here is my hunch, just in case, it may be useful for someone.

My project file structure is as follows: -

 F/ F/Debug/ <--#X contains .exe,.exp,.ilk,.lib,.pdb; one file per type F/Release/ F/F/ <-- contains all my .cpp,.h; F/F/Debug/ <--#Y contains many .obj of my own code, .pch, .log, .tlog F/F/Release/ 

I deleted everything in #X , but not #Y .
Removing all .obj in #Y may be the action that solves the problem.

I will need to test it more to find out how reliable this approach is ...
Please note that all of the above questions are still unanswered.

+5
source share

Source: https://habr.com/ru/post/1263031/


All Articles