[英]Getting Qt to work in Fedora 12
Qt默认安装在Fedora 12中。尝试了hello world程序:
#include </usr/include/QtGui/QApplication>
#include </usr/include/QtGui/QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton hello("Hello world!");
hello.show();
return app.exec();
}
使用常规编译g ++ -o helloWorld helloWorld.cpp,它显示:
/tmp/ccfEv7zR.o:在函数
main': helloWorld.cpp:(.text+0x2a): undefined reference to
QApplication :: QApplication(int&,char **,int)的main': helloWorld.cpp:(.text+0x2a): undefined reference to
helloWorld.cpp :(。text + 0x53) :未定义引用QPushButton::QPushButton(QString const&, QWidget*)' helloWorld.cpp:(.text+0x8b): undefined reference to
QApplication :: exec()'helloWorld.cpp :(。text + 0x99):未定义引用到QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to
QPushButton ::QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to
helloWorld.cpp :(。text + 0xc0):对QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to
〜QApplication的未定义引用QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to
QApplication ::QApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to
/tmp/ccfEv7zR.o:在函数QString::QString(char const*)': helloWorld.cpp:(.text._ZN7QStringC1EPKc[QString::QString(char const*)]+0x1d): undefined reference to
QString :: fromAscii_helper(char const *,int)'/tmp/ccfEv7zR.o:在函数QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to
〜QStringQString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to
QString :: fre的QString::~QString()': helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d): undefined reference to
e(QString :: Data *)'collect2:ld返回1退出状态bash:./helloWorld:没有这样的文件或目录
与
qmake -project; qmake; make
表明:
/usr/lib64/qt-3.3/bin/moc /usr/include/QtGui/qapplication.h -o /usr/include/QtGui/moc_qapplication.cpp moc:无法创建/usr/include/QtGui/moc_qapplication.cpp使: * [/usr/include/QtGui/moc_qapplication.cpp]错误1
知道如何使其工作吗?
更新:
我的cpp已经在非只读目录中。 现在我将标题更改为
#include <QApplication>
#include <QPushButton>
它显示此错误:
g ++ -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE = 2 -fexceptions -fstack-protector --param = ssp-buffer-size = 4 -m64 -mtune = generic -DQT_NO_DEBUG- I / usr / lib64 / qt-3.3 / mkspecs / default -I。 -一世。 -I / usr / lib64 / qt-3.3 / include -o helloWorld.o helloWorld.cpp
helloWorld.cpp:1:25:错误:
QApplication:没有此类文件或
目录helloWorld.cpp:2:24:错误:
QPushButton:没有这样的文件或目录
helloWorld.cpp:在函数'int中
main(int,char * )':helloWorld.cpp:7:
错误:未声明“ QApplication”
在此范围helloWorld.cpp:7:错误:
预期的';' 在“应用”之前
helloWorld.cpp:8:错误:“ QPushButton”
在这方面没有申明
helloWorld.cpp:8:错误:预期为';'
在“ hello” helloWorld.cpp:9之前:
错误:未在其中声明“ hello”
此范围helloWorld.cpp:10:错误:
未在此范围内声明“ app”
helloWorld.cpp:在全球范围内:
helloWorld.cpp:5:警告:未使用
参数'argc'helloWorld.cpp:5:
警告:未使用的参数“ argv”使:
* * [helloWorld.o]错误1
问题在于/ usr / include / QtGui /是“受保护的” 。 (您没有对该目录的写权限)
将helloworld.cpp移至您具有写访问权的目录。 例如/ home / yourusername /helloworld/helloworld.cpp
更改:
#include </usr/include/QtGui/QApplication>
#include </usr/include/QtGui/QPushButton>
至:
#include <QApplication>
#include <QPushButton>
然后尝试:
qmake -project
qmake
make
我建议您阅读有关使用qmake的内容 。 然后,您将理解为什么会遇到第一个错误:qmake通过为您创建一个Makefile来帮助您获取包含和正确的库步骤。
编辑:
要检查的另一件事是确保qmake在您的路径中,并且可以选择是否设置了QTDIR环境变量。
从编译日志中可以清楚地看到您正在使用Qt 3.3。
这解释了为什么您仍然无法使它正常工作。 Qt 4.0中引入了CamelCase样式的标头,例如QPushButton。
您很可能是偶然使用Qt 3.3的。 确保从Qt 4运行qmake。在许多Linux发行版中,它以qmake-qt4
形式安装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.