qmake 生成的 Makefile 中缺少 QtWebKit 依赖项
我刚刚开始使用 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.conf LIBS 变量也缺少 -lQtWebKit。手动添加这些会使编译成功。我做错了什么?我需要添加什么才能使 qmake 生成正确的 Makefile?
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();
}
I ran:
qmake -project
qmake hello.pro
make
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();
}
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
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将:添加
到您的
.pro
文件中,然后重新运行 qmake。qmake -project
不会尝试猜测代码中需要哪些模块。如果您有多个模块,通常的语法如下:
You need to add:
to your
.pro
file, and re-run qmake.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: