: 일반 컴파일와12
#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 ++는 인 helloWorld helloWorld.cpp, 그것은 보여줍니다 -o :
/tmp/ccfEv7zR.o: In function
main': helloWorld.cpp:(.text+0x2a): undefined reference to
QApplication::QApplication(int&, char**, int)' helloWorld.cpp:(.text+0x53): undefined reference toQPushButton::QPushButton(QString const&, QWidget*)' helloWorld.cpp:(.text+0x8b): undefined reference to
QApplication::exec()' helloWorld.cpp:(.text+0x99): undefined reference toQPushButton::~QPushButton()' helloWorld.cpp:(.text+0xac): undefined reference to
QPushButton::~QPushButton()' helloWorld.cpp:(.text+0xc0): undefined reference toQApplication::~QApplication()' helloWorld.cpp:(.text+0xdc): undefined reference to
QApplication::~QApplication()' /tmp/ccfEv7zR.o: In functionQString::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 functionQString::~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
PATH 및 QDIR 환경 변수를 알려주십시오. "커스텀"Qt를 설치했거나 한 단계에서 직접 컴파일 했습니까? –
@Derick : 당신 downvoter 있습니까? 방금이 질문에 대한 "인기 질문"배지를 받았습니다. 나는 custom qt를 설치하지 않았다.내 게시물의 첫 번째 줄에서 Fedora에 이미 기본적으로 설치되었다고 언급했습니다. QT로 처음으로 일하고 있습니다. QDIR에 대해 어떻게 알 수 있습니까? – Nav
Nope was not me :) OS와 Qt를 업데이트하는 것이 좋습니다. Qt 문서와 예제 코드가있는 Fedora 패키지를 찾으려고하지 마십시오. 여기에 Qt3으로 컴파일되는 코드가있는 샘플이 있습니다. ("오래된"페도라를 사용하는 이유가 있습니까? 새 상자를 설치해야할까요? VirtualBox 또는 [Vagrant] (http://www.vagrantup.com/)와 같은 가상 머신을 사용해 보셨습니까?) –