Make在更改时不会重建标头

Dri*_*ise 8 c++ qt makefile compilation header-files

我有一个项目,我经常修改标题,当我这样做,忘记make clean那时make,我得到各种奇怪的行为.我目前正在使用Qt Creator作为我的IDE,但我已经看到这发生在一个独立于Qt的项目上.我的项目变得相当大,每次我更改标题时都必须重建,这种方法正变得无用.有什么想法吗?

备查:

如果使用QMake系统:

DEPENDPATH += . \
    HeaderLocation1/ \
    HeaderLocation2/ \
    HeaderLocation2/HeaderSubLocation1/ \
    HeaderLocation2/HeaderSubLocation2/ \
    HeaderLocation2/HeaderSubLocation3/ \
    HeaderLocation2/HeaderSubLocation4/ \
    HeaderLocation2/HeaderSubLocation5/ \
    HeaderLocation3/ \
    HeaderLocation3/HeaderSubLocation1/ \
    HeaderLocation3/HeaderSubLocation2/ \

lee*_*mes 5

重新运行qmake.这将生成一个具有适当依赖关系的新Makefile.

例:

文件file.h如下所示:

#include "some.h"
#include "header.h"
#include "files.h"
...
Run Code Online (Sandbox Code Playgroud)

并且file.cpp看起来像以下内容:

#include "file.h"
...
Run Code Online (Sandbox Code Playgroud)

在你的.pro:

HEADERS += file.h some.h header.h files.h
SOURCES += file.cpp
Run Code Online (Sandbox Code Playgroud)

将产生以下结果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
Run Code Online (Sandbox Code Playgroud)


nhe*_*hed 4

对您的 IDE 一无所知,并且不确定它是否相关,并且由于您没有包含您的 makefile - 我只会说明显而易见的情况 - 您是否使用任何自动生成的依赖项?

对于 g++,我使用该-MD标志,然后在 makefile 中包含$(wildcard bin/*.d)(取决于创建目标文件的位置,我的目标文件是在“bin”中创建的)

还要确保删除干净构建上的 dep 文件