我一直在试图弄清楚为什么Visual Studio没有重新编译我的库项目中所有受头文件更改影响的编译单元。
假设我有以下头文件TestA.h
:
class TestA
{
public:
int GetNumber() { return 0 };
std::string GetString(); // implemented in TestA.cpp
}
假设我有三个.cpp文件,分别为TestA.cpp、TestB.cpp和TestC.cpp。
TestA.cpp仅包含TestA函数的实现。
然而,TestB.cpp和TestC.cpp都遵循下列格式:
#include "TestA.h"
....
TestA* aObject = new TestA();
int aNumber = aObject->GetNumber();
...
这就是问题所在,如果我将TestA.h中的函数
GetNumber
更改为GetNumber1
,Visual Studio和MSBuild命令行将只构建TestA.cpp,并成功编译。然后它将使用现在过时的.obj文件生成.lib文件。但是,如果我重新构建,则会出现我预期的错误。我尝试启用/禁用增量链接、最小重建、托管增量构建,但都没有解决问题。
我可以通过删除中间目录中的.obj和.tlog文件来实现所需的行为。
感谢帮助。
谢谢
Sumeth