c++ - 更改时 Make 不会重建 header

标签 c++ qt compilation makefile header-files

我有一个项目,我定期修改 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/

相关文章:

c++ - 多个 'const reference' 变量可以共享同一个内存吗?

c++ - 如果我已经重载了 << 和 >> 运算符,如何获取 ostream

c++ - QGraphicsView视口(viewport)矩形问题

compiler-errors - 如何在OCaml中编译多个文件?

c++ - 当我想在外面抓东西时无法编译 lambda

c++ - 如何返回一个 lambda 函数?

c++ - 指向带有 2 个参数的 WINAPI 函数的 Typedef 指针

c++ - sleep 影响哪个虚拟成员函数被std::thread调用?

ios - Xcode 9.2 陷入编译 Swift 3.2 项目的困境

c++ - 包含库时找不到 Qt shared_ptr