12

2011-04-05 3 views
0
Qt는 페도라 12에 기본적으로 안녕하세요 세계 프로그램을 시도 설치되어

: 일반 컴파일와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 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

+0

PATH 및 QDIR 환경 변수를 알려주십시오. "커스텀"Qt를 설치했거나 한 단계에서 직접 컴파일 했습니까? –

+0

@Derick : 당신 downvoter 있습니까? 방금이 질문에 대한 "인기 질문"배지를 받았습니다. 나는 custom qt를 설치하지 않았다.내 게시물의 첫 번째 줄에서 Fedora에 이미 기본적으로 설치되었다고 언급했습니다. QT로 처음으로 일하고 있습니다. QDIR에 대해 어떻게 알 수 있습니까? – Nav

+0

Nope was not me :) OS와 Qt를 업데이트하는 것이 좋습니다. Qt 문서와 예제 코드가있는 Fedora 패키지를 찾으려고하지 마십시오. 여기에 Qt3으로 컴파일되는 코드가있는 샘플이 있습니다. ("오래된"페도라를 사용하는 이유가 있습니까? 새 상자를 설치해야할까요? VirtualBox 또는 [Vagrant] (http://www.vagrantup.com/)와 같은 가상 머신을 사용해 보셨습니까?) –

답변

3

문제는 그는/usr/포함/QtGui/"보호"입니다입니다. (해당 디렉토리에 대한 쓰기 권한이 없습니다.)

helloworld.cpp를 쓰기 권한이있는 디렉토리로 이동하십시오. 예/홈/username이 /helloworld/helloworld.cpp를 들어

은 변경 :

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

하려면 : 1

#include <QApplication> 
#include <QPushButton> 

시도 :

qmake -project 
qmake 
make 

을 내가 읽고 제안 조금 올라가서 using qmake. 그런 다음 첫 번째 오류가 발생한 이유를 이해하게됩니다. qmake는 Makefile을 작성하여 포함 및 올바른 라이브러리 단계를 얻을 수 있도록 도와줍니다.

편집 :

또 다른 것은 확인이 qmake를이 경로에 선택적으로 QTDIR 환경 변수가 설정되어 있는지 확인하는 것입니다.

+0

경로에서 QTDIR 변수와 qmake를 확인하십시오. 그들이 같은 장소를 가리키고 있는지 확인하십시오. 또한 버전이 엉망이 아닌지 확인하십시오. Linux는 "기본 Qt 라이브러리"를 가지고 있으며 사용자 정의 라이브러리를 설치할 수 있습니다. 사용자 정의를 설치 한 경우 QTDIR이 가리키는 경로의 첫 번째 경로인지 확인하십시오. –

+0

@Nav : PATH 및 QDIR 환경 변수를 표시하십시오. "커스텀"qt를 설치했거나 스스로 컴파일 했습니까? –

+0

** $ PATH **는 "bash : /usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib64/ccache:/usr/local/bin :/home/username/bin :. : 해당 파일이나 디렉토리가 없습니다. "및 ** $ QTDIR **은"bash를 보여줍니다. "/ usr/bin :/bin :/usr/local/sbin :/usr/sbin :/sbin : : /usr/lib64/qt-3.3 : 디렉토리는 "입니다. Qt를 설치할 필요가 없었습니다. Fedora 12와 함께 미리 설치되었습니다. – Nav

0

컴파일 로그에서 Qt 3.3을 사용하고 있음이 확실합니다.

이것은 왜 여전히 작동하지 않는지 설명합니다. QPushButton과 같은 CamelCase 스타일의 헤더가 Qt 4.0에 도입되었습니다.

실수로 Qt 3.3을 사용했을 가능성이 큽니다. Qt 4에서 qmake를 실행했는지 확인하십시오. 많은 Linux 배포판에서 이것은 qmake-qt4으로 설치됩니다.

+0

먼저 Qt를 설치하지 않았습니다. Fedora와 함께 사전 설치되었습니다. 둘째, Qt 폴더에 camelCase 헤더가 있습니다. 헤더에는 "#include "한 줄만 포함됩니다. 어쨌든, 나는 재 설치가 더 좋을 것이라고 생각한다. – Nav

+0

Qt를 설치했는지 또는 사전 설치했는지 여부는 내가 말한 것과 관련이 있는지 이해할 수 없습니다. "Qt 폴더"란 무엇입니까? 어쩌면 Qt 3과 Qt 4가 모두 설치되어있을 것입니다. (사실이 경우 일 가능성이 큽니다.) – rohanpm

관련 문제