You are not logged in.

#1 2011-08-03 23:30:39

neurobot
Member
Registered: 2011-07-11
Posts: 2

Qt g++ "fatal error: QtGui : No such file or directory"

I'm trying to program GUIs with Qt for the first time.  I'm still extremely new (started reading about it last night) to C++, although I've been programming in C for a while.  From the arch package repo, I've downloaded qt, qt-private-headers, and qt-doc.  I haven't changed any directories or permissions around.  Inside the directory /usr/share/doc/qt/examples/widgets/calculator I try to compile the example program with

 g++ main.cpp -o main 

and I get the error:

main.cpp:41:24: fatal error: QApplication: No such file or directory
compilation terminated.

When I add the option   

 g++ main.cpp -o main -I/usr/include/QtGui

, I get a 'permission denied', and when I execute the entire command with sudo, I get a trillion errors, all remarkably the same:

/tmp/ccyHSlXv.o: In function `main':
main.cpp:(.text+0x28): undefined reference to `QApplication::QApplication(int&, char**, int)'
main.cpp:(.text+0x3c): undefined reference to `Calculator::Calculator(QWidget*)'
main.cpp:(.text+0x4d): undefined reference to `QApplication::exec()'
main.cpp:(.text+0x67): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0x8c): undefined reference to `QApplication::~QApplication()'
/tmp/ccyHSlXv.o: In function `QString::~QString()':
main.cpp:(.text._ZN7QStringD2Ev[_ZN7QStringD5Ev]+0x23): undefined reference to `QString::free(QString::Data*)'
/tmp/ccyHSlXv.o: In function `Calculator::~Calculator()':
main.cpp:(.text._ZN10CalculatorD2Ev[_ZN10CalculatorD5Ev]+0xc): undefined reference to `vtable for Calculator'
main.cpp:(.text._ZN10CalculatorD2Ev[_ZN10CalculatorD5Ev]+0x16): undefined reference to `vtable for Calculator'
main.cpp:(.text._ZN10CalculatorD2Ev[_ZN10CalculatorD5Ev]+0x3d): undefined reference to `QDialog::~QDialog()'
main.cpp:(.text._ZN10CalculatorD2Ev[_ZN10CalculatorD5Ev]+0x75): undefined reference to `QDialog::~QDialog()'
collect2: ld returned 1 exit status

I have absolutely no clue what's wrong.  If anyone has had a similar problem getting Qt to work in Arch, please shout out.

Offline

#2 2011-08-03 23:56:08

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Qt g++ "fatal error: QtGui : No such file or directory"

I think you need to link it against the qt library? http://ubuntuforums.org/showthread.php?p=11092451
I doubt it's Arch-related.

I would suggest copying the example calculator files to another directory. This is what I've done:

[karol@black foo7]$ qmake calculator.pro 

It generates a Makefile

[karol@black foo7]$ ls
total 44K
-rw-r--r-- 1 2,5K 08-04 02:14 button.cpp
-rw-r--r-- 1 2,3K 08-04 02:14 button.h
-rw-r--r-- 1  12K 08-04 02:14 calculator.cpp
-rw-r--r-- 1 3,3K 08-04 02:14 calculator.h
-rw-r--r-- 1  468 08-04 02:14 calculator.pro
-rw-r--r-- 1 2,2K 08-04 02:14 main.cpp
-rw-r--r-- 1 9,6K 08-04 02:16 Makefile
[karol@black foo7]$ make
g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -fno-strict-aliasing -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -o button.o button.cpp
g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -fno-strict-aliasing -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -o calculator.o calculator.cpp
g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -fno-strict-aliasing -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -o main.o main.cpp
/usr/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. button.h -o moc_button.cpp
g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -fno-strict-aliasing -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -o moc_button.o moc_button.cpp
/usr/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. calculator.h -o moc_calculator.cpp
g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -fno-strict-aliasing -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -o moc_calculator.o moc_calculator.cpp
g++ -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-O1 -o calculator button.o calculator.o main.o moc_button.o moc_calculator.o    -L/usr/lib -lQtGui -lQtCore -lpthread 
[karol@black foo7]$ ls
total 148K
-rw-r--r-- 1 2,5K 08-04 02:14 button.cpp
-rw-r--r-- 1 2,3K 08-04 02:14 button.h
-rw-r--r-- 1 1,8K 08-04 02:17 button.o
-rwxr-xr-x 1  43K 08-04 02:17 calculator
-rw-r--r-- 1  12K 08-04 02:14 calculator.cpp
-rw-r--r-- 1 3,3K 08-04 02:14 calculator.h
-rw-r--r-- 1  21K 08-04 02:17 calculator.o
-rw-r--r-- 1  468 08-04 02:14 calculator.pro
-rw-r--r-- 1 2,2K 08-04 02:14 main.cpp
-rw-r--r-- 1 3,2K 08-04 02:17 main.o
-rw-r--r-- 1 9,6K 08-04 02:16 Makefile
-rw-r--r-- 1 2,0K 08-04 02:17 moc_button.cpp
-rw-r--r-- 1 7,4K 08-04 02:17 moc_button.o
-rw-r--r-- 1 3,5K 08-04 02:17 moc_calculator.cpp
-rw-r--r-- 1 9,8K 08-04 02:17 moc_calculator.o
[karol@black foo7]$ ./calculator

Works!

Last edited by karol (2011-08-04 00:23:52)

Offline

#3 2011-08-04 00:54:38

neurobot
Member
Registered: 2011-07-11
Posts: 2

Re: Qt g++ "fatal error: QtGui : No such file or directory"

Genius!!

Thank you!  It works great.  And looks good too.  I've never heard of qmake though.  Where do you recommend I go to read about it, so I can make my own qmake files.  I'm extremely new at this; I've never made more than a 4 line Makefile before.


Also, I'm either very lucky you happened to show up so soon, or these forums are amazing in general.

Offline

#4 2011-08-04 00:59:46

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Qt g++ "fatal error: QtGui : No such file or directory"

I'm even "newer to qt" than you as I'm not a dev at all and I simply googled your error message and proceeded from there.

Suggested links: http://doc.qt.nokia.com/4.7/gettingstartedqt.html and http://doc.qt.nokia.com/4.7-snapshot/qmake-using.html

Offline

Board footer

Powered by FluxBB