我有一个项目,我定期修改 header ,当我这样做时,忘记了 make clean
然后 make
,我得到了各种奇怪的行为。我目前正在使用 Qt Creator 作为我的 IDE,但我已经在独立于 Qt 的项目中看到过这种情况。我的项目变得相当大,每次更改 header 时都必须重建,这变得效率低下。有什么想法吗?
供将来引用:
如果使用 QMake 系统:
DEPENDPATH += . \ HeaderLocation1/ \ HeaderLocation2/ \ HeaderLocation2/HeaderSubLocation1/ \ HeaderLocation2/HeaderSubLocation2/ \ HeaderLocation2/HeaderSubLocation3/ \ HeaderLocation2/HeaderSubLocation4/ \ HeaderLocation2/HeaderSubLocation5/ \ HeaderLocation3/ \ HeaderLocation3/HeaderSubLocation1/ \ HeaderLocation3/HeaderSubLocation2/ \
最佳答案
重新运行 qmake
。这将生成一个具有适当依赖关系的新 Makefile。
示例:
文件 file.h
如下所示:
#include "some.h"
#include "header.h"
#include "files.h"
...
和 file.cpp
如下所示:
#include "file.h"
...
并在您的 .pro
中:
HEADERS += file.h some.h header.h files.h
SOURCES += file.cpp
将在生成的 Makefile
中生成以下内容:
file.o: ../src/file.cpp ../src/file.h \
../src/some.h \
../src/header.h \
../src/files.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o file.o ../src/file.cpp
关于c++ - 更改时 Make 不会重建 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10637762/