问题
I´ve got one project, where all my .h and .cpp files are included. This project builds my application. Another project has all my unit tests in it, which require the same .h and .cpp files as the first project. So everytime I add a new file to my first project I have to add it to the second project too, which is why I tried to automate that step.
For this I tried to use the files(glob) function of qmake, which looks basically like this:
HEADERS += \
someotherstuff.h \
files(../Core/DriveProgramInterface/*.h) \
files(../Core/DriveProgramWizard/*.h)
SOURCES += \
someotherstuff.cpp \
files(../Core/*.cpp) \
files(../Core/DriveProgramInterface/*.cpp) \
files(../Core/DriveProgramWizard/*.cpp)
So, while it works well with the headers it doesn´t work with the sources at all. When I try to compile I get the following error:
No rule to make target 'files(../Core/DriveProgramWizard/.cpp), needed by 'debug/.o'. Stop
So I looked at my MakeFile and I´ve found this:
SOURCES = \
someotherstuff.cpp \
files(..\Core\*.cpp) \
files(..\Core\DriveProgramInterface\*.cpp) \
files(..\Core\DriveProgramWizard\*.cpp) \
OBJECTS = \
someotherstuff.cpp \
debug/*.o \
debug/*.o \
debug/*.o \
So I´m thinking, maybe the problem is, that the glob isn´t resolved in the MakeFile, but instead it tries to generate *.o files. I´m really not the least bit sure, if that is right, so if there´s some other reason why this doesn´t work, feel free to point me to it.
Also, if you´ve got any suggestions how I could make this work (with the files() function or without, I don´t care), I´d be very grateful.
回答1:
I found out recently that qmake expands simple expressions like *.cpp automatically, without needing any specially globbing functions.
So I would suggest changing your SOURCES line to this:
SOURCES += someotherstuff.cpp
SOURCES += ../Core/*.cpp
SOURCES += ../Core/DriveProgramInterface/*.cpp
SOURCES += ../Core/DriveProgramWizard/*.cpp
回答2:
In some cases just adding: SOURCES += ../OtherDir/*.cpp
does not work and running the generated Makefile complains that:
No rule to make target '/../OtherDir/*.cpp', needed by 'release/*.o' [or 'debug/*.o']
In such a case, the solution is to wrap the $$qoute($$PWD/...)
around the paths which have wild card *:
SOURCES += $$quote($$PWD/../OtherDir/*.cpp)
HEADERS += $$quote($$PWD/../OtherDir/*.h)
This way a working Makefile
is created and the build is successful.
I think one of the cases is when one adds *.cpp/*.h
to a sub-project which is nested in a super project (i.e a project with TEMPLATE=subdir
in its project .pro file).
It may also help, mentioning that I work on Windows/MinGW32
platform and the problem may be related to this platform.
来源:https://stackoverflow.com/questions/9464003/no-rule-to-make-target-error-with-undocumented-filesglob-function