l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
December 2: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2002 Apr 07 15:25

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] kde/qt programming question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] kde/qt programming question



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
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.