[vox-tech] kde/qt programming question

Peter Jay Salzman vox-tech@lists.lugod.org
Sun, 7 Apr 2002 10:54:18 -0700


hi patrick,

before going into an answer, just a minor point about terminology.  the
include files (ie- stdio.h) aren't libraries.  they provide things like
function declarations (prototypes) and defines.  they don't actually
contain object code associated with a library.

libraries are usually named along the lines of liblibrary.a or
liblibrary.so.  see www.dirac.org/linux/libraries.html


begin Patrick Stockton <codejnki@codejnki.com> 
> I'm starting to read a few tutorials on kde/qt programming
> 
> One of the first programs they have you do has the following source:
> 
> #include <qapplication.h>
> #include <qpushbutton.h>
> 
> int main( int argc, char **argv )
> {
> QApplication a( argc, argv );
> 
> QPushButton hello( "Hello world!" );
> hello.resize( 100, 30 );
> 
> a.setMainWidget( &hello );
> hello.show();
> return a.exec();
> }
> 
> When I first tried to compile it using "g++ 1.cpp -o 1" it gave me errors:
> 1.cpp:1:30: qapplication.h: No such file or directory
> 1.cpp:2:29: qpushbutton.h: No such file or directory
> 
> That said to me that it couldn't find the right libraries.
> So from inside my /usr/include directory I did a:
> ln -s /usr/lib/qt2/include qt2
> 
> and then modified the two include lines to read:
> #include <qt2/qapplication.h>
> #include <qt2/qpushbutton.h>
 
this may not work if these header files want to import other header
files because gcc won't find the other files.  it'll find the two that
you mention explicitly above, but not anything else unless you modify
the path names of all the header files these two files import.

thankfully, there's a better solution.

> Well now I am getting:
> 
> In file included from /usr/include/qt2/qobjectdefs.h:42,
>                  from /usr/include/qt2/qwindowdefs.h:43,
>                  from /usr/include/qt2/qwidget.h:42,
>                  from /usr/include/qt2/qapplication.h:42,
>                  from 1.cpp:1:
> /usr/include/qt2/qglobal.h:448:23: qfeatures.h: No such file or directory
> 
> Now qglobal.h and qfeatures.h are both inside the /usr/include/qt2 directory
> so I know it's not a problem of the files not being there.  How or what
> should I edit path/shell variable wise to get the compiler to look in all the
> right spots to find all the right header files.

gcc has an option "-I<dir>" which appends <dir> to the list of
directories that gcc looks in for header files.   so what you want to do
is add

-I/directory/in/which/your/include/files/are/in

to the gcc command line options.   you'll need to use -l to specify the
libraries to link against, of course.   but you'll also prolly need to
use -L too.   -L is like -I, but where -I tells gcc about directories
that contain include files, -L tells gcc about directories that contain
the actual libraries.

> P.S.:
> If anbody knows of a good programming tutorial for c/c++ on linux that goes
> beyond your basic Hello World and on to something more advanced like how to
> write say a basic text editor to teach you things could you send me the link?
>  I've been searching google for a week now and just haven't found quite the
> right thing.
 
my website contains some relevent info: www.dirac.org/linux.  a good
thing to do is to point your browser to nerdbooks.com and use their
search facility.  if you're a lugod member and have your picture on our
membership pages, you get a 10% discount of all in-store purchases.

i would imagine there's a book called something like "programming in the
linux environment" or something like that.  however, these issues are
not linux specific.  the problem you mention will apply to all unicies,
although i'm sure each one has its own nota benes.

but the best way to learn is:

* read man gcc
* ask questions on vox-tech
* make copious use of google group searches

pete