Qmake生成的Makefile中缺少QtWebKit依赖项 [英] QtWebKit dependency missing from qmake generated Makefile
问题描述
我刚刚开始使用Qt(在C ++中),所以我遵循了我在网上找到的"hello,world"示例.我在hello目录中创建了程序hello.cpp:
I just started working with Qt (in C++), so I followed a "hello, world" example I found online. I created the program hello.cpp in the directory hello:
#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了.然后,作为一个有冒险精神的人,我尝试修改文件:
and everything compiled correctly and I was able to run ./hello. Then, being an adventurous person, I tried modifying the file:
#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时,出现以下错误:
I reran the three commands, but now when I run make I get the following error:
hello.cpp:2: fatal error: QtWebKit: No such file or directory
compilation terminated.
make: *** [hello.o] Error 1
我检出了Makefile,并将INCPATH变量定义为
I checked out the Makefile and the INCPATH variable was defined as
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?
It is noticeably missing -I/usr/include/qt4/QtWebKit. The LIBS variable was also missing -lQtWebKit. Adding these manually causes the compilation to succeed. What am I doing wrong? What do I need to add to make qmake generate the correct Makefile?
推荐答案
您需要添加:
QT += webkit
到您的.pro
文件,然后重新运行qmake.
to your .pro
file, and re-run qmake.
qmake -project
不会尝试猜测代码中需要哪些模块.
qmake -project
does not try to guess what modules you need in your code.
如果您有多个模块,通常的语法如下:
If you have more than one module, the usual syntax is like:
QT += webkit xml network
这篇关于Qmake生成的Makefile中缺少QtWebKit依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!