I’m trying to compile a small application using Qt but without using QMake, but whenever I try to run it, I get the following error message:
g++ -c -g -pg -Wall -Wextra -pipe -c -o ../../MOCFiles/moc_projectModel.o ../../MOCFiles/moc_projectModel.cpp
In file included from ../../MOCFiles/moc_projectModel.cpp:10:0:
../../MOCFiles/../Src/ProjectStructure/projectModel.h:4:30: fatal error: QAbstractItemModel: No such file or directory
compilation terminated.
make: *** [../../MOCFiles/moc_projectModel.o] Error 1
This would seem to suggest that I haven’t constructed my $(INCLUDE) variable properly, but it is as follows:
INCLUDE = -I/usr/include/qt4 \
-I/usr/include/qt4/QtGui \
-I/usr/include/qt4/QtCore \
-I/usr/include/qt4/QtXml \
-I/usr/share/qt4/mkspecs/linux-g++ \
-I../../Src/ProjectStructure
and I am able to locate the QAbstractItemModel file in /usr/include/qt4/QtCore/, a directory which is part of my include variable. This is my first time writing a GNU Makefile and I’m not sure what it is I’m doing wrong. For reference, the entire file is included here:
CXX = g++
CXXFLAGS = -c -g -pg -Wall -Wextra -pipe
LINK = g++
LIBS = -L/usr/lib \
-L/usr/lib/i386-linux-gnu \
-lgtest \
-lQtGui \
-lQtCore \
-lQtXml \
-lpthread
INCLUDE = -I/usr/include/qt4 \
-I/usr/include/qt4/QtGui \
-I/usr/include/qt4/QtCore \
-I/usr/include/qt4/QtXml \
-I/usr/share/qt4/mkspecs/linux-g++ \
-I../../Src/ProjectStructure
OBJECTS = ../Objects/main.o \
../Objects/test_projectEntity.o \
../Objects/moc_test_projectModel.o \
../../Objects/projectEntity.o \
../../Objects/projectModel.o \
../../MOCFiles/moc_projectModel.o
../../Binaries/tests: $(OBJECTS)
$(LINK) $^ $(LIBS) -o $@
../Objects/main.o : ../Src/main.cpp
$(CXX) $(CXXFLAGS) $(INCLUDE) ../Src/main.cpp -o ../Objects/main.o
../Objects/moc_test_projectModel.o : ../MOCFiles/moc_test_projectModel.cpp
$(CXX) $(CXXFLAGS) $(INCLUDE) ../MOCFiles/moc_test_projectModel.cpp -o ../Objects/moc_test_projectModel.o
../../MOCFiles/moc_test_projectModel.cpp : ../Src/test_projectModel.cpp
moc ../Src/test_projectModel.cpp -o ../MOCFiles/moc_test_projectModel.cpp
../Objects/test_projectEntity.o : ../Src/test_projectEntity.cpp
$(CXX) $(CXXFLAGS) $(INCLUDE) ../Src/test_projectEntity.cpp -o ../Objects/test_projectEntity.o
clean:
rm -f ../Objects/main.o ../Objects/test_projectEntity.o ../Objects/test_projectModel.o
It looks as if you’re trying to build
../../Binaries/tests. One of the preqs is../../MOCFiles/moc_projectModel.o, but there’s no explicit rule for building that, so Make uses the implicit rule and attempts this:Notice that there’s no mention of
INCLUDEthere. So g++ doesn’t know to look in/usr/include/qt4/QtCore/. The simple solution is to add a rule:Notice that I used automatic variables
$<and$@there, to reduce redundancy and clutter. We could also make it into a pattern rule:This takes care of
moc_projectModel.oand anything else that has the same pattern (source and object both inMOCFiles/). We could make other improvements, but that should be enough to get you up and running.