gpt4 book ai didi

c++ - 让 Qt 在 Fedora 12 中工作

转载 作者:行者123 更新时间:2023-11-28 01:07:00 30 4
gpt4 key购买 nike

Fedora 12默认安装Qt,试过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: In function main':
helloWorld.cpp:(.text+0x2a): undefined
reference to
QApplication::QApplication(int&, char**, int)' helloWorld.cpp:(.text+0x53): undefined reference to QPushButton::QPushButton(QString
const&, QWidget*)'
helloWorld.cpp:(.text+0x8b): undefined
reference to
QApplication::exec()' helloWorld.cpp:(.text+0x99): undefined reference to QPushButton::~QPushButton()'
helloWorld.cpp:(.text+0xac): undefined
reference to
QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xc0): undefined reference to QApplication::~QApplication()'
helloWorld.cpp:(.text+0xdc): undefined
reference to
QApplication::~QApplication()' /tmp/ccfEv7zR.o: In function 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: In function QString::~QString()':
helloWorld.cpp:(.text._ZN7QStringD1Ev[QString::~QString()]+0x2d):
undefined reference to
QString::free(QString::Data*)' collect2: ld returned 1 exit status bash: ./helloWorld: No such file or directory

qmake -project;qmake;make

它显示:

/usr/lib64/qt-3.3/bin/moc /usr/include/QtGui/qapplication.h -o /usr/include/QtGui/moc_qapplication.cpp moc: Cannot create /usr/include/QtGui/moc_qapplication.cpp make: * [/usr/include/QtGui/moc_qapplication.cpp] Error 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. -I/usr/lib64/qt-3.3/include -o helloWorld.o helloWorld.cpp
helloWorld.cpp:1:25: error:
QApplication: No such file or
directory helloWorld.cpp:2:24: error:
QPushButton: No such file or directory
helloWorld.cpp: In function ‘int
main(int, char*)’: helloWorld.cpp:7:
error: ‘QApplication’ was not declared
in this scope helloWorld.cpp:7: error:
expected ‘;’ before ‘app’
helloWorld.cpp:8: error: ‘QPushButton’
was not declared in this scope
helloWorld.cpp:8: error: expected ‘;’
before ‘hello’ helloWorld.cpp:9:
error: ‘hello’ was not declared in
this scope helloWorld.cpp:10: error:
‘app’ was not declared in this scope
helloWorld.cpp: At global scope:
helloWorld.cpp:5: warning: unused
parameter ‘argc’ helloWorld.cpp:5:
warning: unused parameter ‘argv’ make:
*
* [helloWorld.o] Error 1

最佳答案

问题是/usr/include/QtGui/是“ protected ”。 (您对该目录没有写权限)

将您的 helloworld.cpp 移动到您具有写入权限的目录。例如/home/您的用户名/helloworld/helloworld.cpp

改变:

#include </usr/include/QtGui/QApplication>
#include </usr/include/QtGui/QPushButton>

收件人:

#include <QApplication>
#include <QPushButton>

然后尝试:

qmake -project
qmake
make

我建议您阅读一下 using qmake .然后您就会明白为什么会出现第一个错误:qmake 通过为您创建一个 Makefile 来帮助您获得包含和正确的库步骤。

编辑:

另一件要检查的事情是确保 qmake 在您的路径中,并且可以选择是否设置了 QTDIR 环境变量。

关于c++ - 让 Qt 在 Fedora 12 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5550549/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com