Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2019 not building all cpp files when a header file changes

I have been trying to figure out why visual studio has not been recompiling all the compilation units affected by a header file change in my Library project.

Lets say I have the following header file TestA.h:

class TestA
{
    public:
    int GetNumber() { return 0 };

    std::string GetString(); // implemented in TestA.cpp

}

Lets say I then have 3 .cpp files TestA.cpp TestB.cpp TestC.cpp

TestA.cpp Only contains the function implementations for TestA

However both TestB.cpp and TestC.cpp follow something of the sort:

#include "TestA.h"

....

TestA* aObject = new TestA();

int aNumber = aObject->GetNumber();

...

This is where the problem now lays, if I change the function GetNumber in TestA.h to GetNumber1 Visual studio and msbuild command line will only build TestA.cpp and it will succeed in compiling. It will then generate the .lib using the now stale .obj files. If I however rebuild then I get the errors that I do expect. I have tried enabling/disabling Incremental linking, minimal rebuilding, Managed Incremental Build.

I can achieve the desired behavior by deleting the .obj and the .tlog files from my intermediate directory.

Any help is appreciated

Thanks Sumeth

like image 950
Sumeth Avatar asked May 01 '26 11:05

Sumeth


1 Answers

So after exhausting all my ideas I decided to try and just recreate the project. And that fixed it! Not sure what exactly happened but deleting all the vcxproj files and recreating the vcxproj from scratch fixed my issue. Not sure what exactly changed but that seemed to solve it

like image 189
Sumeth Avatar answered May 03 '26 10:05

Sumeth