# Qt code won't compile, not including correct files.



## caesius (Dec 27, 2009)

I delving into Qt4 GUI programming, but I can't compile this:


```
#include <QApplication>
 #include <QPushButton>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QPushButton hello("Hello world!");
     hello.resize(100, 30);

     hello.show();
     return app.exec();
 }
```

the error is:


```
> gcc -o qt qt.cpp
qt.cpp:1:24: error: QApplication: No such file or directory
qt.cpp:2:23: error: QPushButton: No such file or directory
qt.cpp: In function 'int main(int, char**)':

[BLAH BLAH BLAH]
>
```

but even when I explicitly give the include paths:


```
//#include <QApplication>
#include "/usr/local/include/qt4/QtGui/QApplication"
//#include <QPushButton>
#include "/usr/local/include/qt4/QtGui/QPushButton"
```

I get this:


```
> gcc -o qt qt.cpp
In file included from /usr/local/include/qt4/QtGui/QApplication:1,
                 from qt.cpp:2:
/usr/local/include/qt4/QtGui/qapplication.h:45:37: error: QtCore/qcoreapplication.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:46:31: error: QtGui/qwindowdefs.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:47:27: error: QtCore/qpoint.h: No such file or directory
/usr/local/include/qt4/QtGui/qapplication.h:48:26: error: QtCore/qsize.h: No such file or directory

[CLIPPED THE REST, YOU GET THE POINT]
```

I *know*, I could probably use qmake to build this, but the inquisitive part of me is jumping out; it's still just a C++ program, why can't I compile it?

Thanks for any nudges in the right direction.


----------



## expl (Dec 27, 2009)

Try compiling like this:

```
g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -L/usr/local/lib/qt4 -lQtGui -lQtCore -o qt qt.cpp
```


----------



## ta0kira (Jan 6, 2010)

expl said:
			
		

> Try compiling like this:
> 
> ```
> g++ -I/usr/local/include/qt4/QtGui -I/usr/local/include/qt4 -L/usr/local/lib/qt4 -lQtGui -lQtCore -o qt qt.cpp
> ```


If /usr/local/lib/qt4 isn't in a path that [CMD=""]ldconfig[/CMD] checks (extremely likely) the compiled program might not run without preceding the Qt libs with [CMD=""]-Xlinker -rpath /usr/local/lib/qt4[/CMD]. Explicitly naming the Qt libraries by full path-name might be better.
Kevin Barry


----------



## SIFE (Jan 31, 2011)

Even this thread is old, I put this just for knowing the cause of problem.

```
#qmake-qt4 -project
#qmake-qt4 
#make
```
This is for QT4, if you use QT3  try this:

```
#qmake -project
#qmake
#make
```


----------

