我刚开始使用 Qt(C++),所以我遵循了一个我在网上找到的“hello, world”示例。我在目录 hello 中创建了程序 hello.cpp:
#include <QtGui>
int main(int argc, char *argv[]) {
QApplication app (argc, argv);
QLabel label ("Hello, world!");
label.show();
return app.exec();
}
我跑了:
qmake -project
qmake hello.pro
make
一切都正确编译,我能够运行 ./hello。然后,作为一个有冒险精神的人,我尝试修改文件:
#include <QtGui>
#include <QtWebKit>
int main(int argc, char *argv[]) {
QApplication app (argc, argv);
QLabel label ("Hello, world!");
QWebPage page;
label.show();
return app.exec();
}
我重新运行了这三个命令,但是现在当我运行 make 时出现以下错误:
hello.cpp:2: fatal error: QtWebKit: No such file or directory
compilation terminated.
make: *** [hello.o] Error 1
我检查了 Makefile,INCPATH 变量定义为
INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I.
明显缺少 -I/usr/include/qt4/QtWebKit。 LIBS 变量也丢失了 -lQtWebKit。手动添加这些会导致编译成功。我究竟做错了什么?我需要添加什么才能使 qmake 生成正确的 Makefile?
最佳答案
你需要添加:
QT += webkit
到你的 .pro
文件,然后重新运行 qmake。
qmake -project
不会尝试猜测您的代码中需要哪些模块。
如果你有多个模块,通常的语法是这样的:
QT += webkit xml network
关于c++ - qmake 生成的 Makefile 中缺少 QtWebKit 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6643176/