[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Hello World newbie woes
From: "Martin Welch" <martin () welch ! eclipse ! co ! uk>
Date: 2004-03-31 10:57:33
Message-ID: GIEKKMAAMELBNKEJJKHGCECFCMAA.martin () welch ! eclipse ! co ! uk
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I'm having difficulty getting KHello to build and run on my new Mandrake 10
box.
Following the tutorial on kdevelop.kde.org I finally managed to get this to
build and run:
--------------khello.cpp------------
#include <kapp.h>
#include <kmainwindow.h>
int main( int argc, char **argv )
{
KApplication a( argc, argv, "khello" );
KMainWindow *w = new KMainWindow();
w->setGeometry(100,100,200,100);
a.setMainWidget( w );
w->show();
return a.exec();
}
--------------build1-----------------
c++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti khello.cpp -o
../khello.o
c++ -L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore $QTDIRqt -ldl -o ../khello
../khello.o
------------------------------------
The next attempt builds but crashes when I try to run it.
--------------main.cpp-------------------
#include "khello.h"
int main( int argc, char **argv )
{
KApplication a( argc, argv, "khello" );
KHello *w = new KHello();
w->setGeometry(100,100,200,100);
a.setMainWidget( w );
w->show();
return a.exec();
}
-------------khello.h-----------------------
#include <kapp.h>
#include <kmainwindow.h>
#include <kmessagebox.h>
#include <qpushbutton.h>
#include <kmenubar.h>
#include <kpopupmenu.h>
class KHello : public KMainWindow
{
Q_OBJECT
public:
KHello();
void closeEvent(QCloseEvent *);
public slots:
void slotHello();
void slotExit();
private:
QPushButton *btnHello;
QPushButton *btnExit;
KMenuBar *menu;
KPopupMenu *file, *help;
};
------------khello.cpp---------------------
#include "khello.moc"
#include <kmessagebox.h>
KHello::KHello() : KMainWindow()
{
btnHello = new QPushButton("Hello", this);
btnHello->setGeometry(45,30,50,25);
btnHello->show();
connect(btnHello, SIGNAL(clicked()), this, SLOT(slotHello()));
btnExit = new QPushButton("Exit", this);
btnExit->setGeometry(105,30,50,25);
btnExit->show();
connect(btnExit, SIGNAL(clicked()), this, SLOT(slotExit()));
file = new KPopupMenu();
file->insertItem("&Hello", this, SLOT(slotHello()));
file->insertItem("&Exit", this, SLOT(slotExit()));
help = helpMenu("KHello\nby Daniel Marjamäki\nUpdated by David Leimbach");
menu = menuBar();
menu->insertItem("&File", file);
menu->insertItem("&Help", help);
}
void KHello::closeEvent(QCloseEvent *e)
{
kapp->beep();
KMainWindow::closeEvent(e);
}
void KHello::slotHello()
{
KMessageBox::information(this, "Hello World!", "Important");
}
void KHello::slotExit()
{
close();
}
---------------build2---------------------
c++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti main.cpp -o main.o
$QTDIR/bin/moc khello.h -o khello.moc
c++ -c -I$KDEDIR/include -I$QTDIR/include -fno-rtti khello.cpp -o khello.o
c++ -L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore $QTDIRqt -ldl -o khello
main.o khello.o
------------------------------------
I'm fairly confident that the source code is right and its my build scripts
that are wrong.
Q1: Why does the output files (hello.o etc) always have an \r appended to
the names?
The only thing in my scripts that's different is that I've changed -qt to
$QTDIRqt since
ld couldn't find qt. My understanding here is -L/blah says the compiler
should look in /blah for libraries and -lfoo says the library is called foo.
At runtime my program 'knows' to load foo but doesn't know where foo
resides. If, OTOH, I use -l/blah/foo my program will expect to load foo from
/blah -- the path is hardcoded.
Q2: On my machine then (L/blah -lfoo) == (-l/blah/foo) ?
Q3: Am I talking rubbish? :)
Could anyone advise?
Thanks,
Martin
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>I'm having
difficulty getting KHello to build and run on my new Mandrake 10
box.</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>Following the
tutorial on kdevelop.kde.org I finally managed to get this to build and
run:</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2>--------------khello.cpp------------</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>#include
<kapp.h><BR>#include <kmainwindow.h></FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>int main( int
argc, char **argv )<BR>{<BR> KApplication a( argc, argv, "khello"
);<BR> KMainWindow *w = new KMainWindow();<BR>
w->setGeometry(100,100,200,100);</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>
a.setMainWidget( w );<BR> w->show();<BR> return
a.exec();<BR>}<BR>--------------build1-----------------</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>c++ -c
-I$KDEDIR/include -I$QTDIR/include -fno-rtti khello.cpp -o ../khello.o<BR>c++
-L$KDEDIR/lib -L$QTDIR/lib -lkdeui -lkdecore $QTDIRqt -ldl -o ../khello
../khello.o<BR>------------------------------------</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>The next attempt
builds but crashes when I try to run it.</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2>--------------main.cpp-------------------</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>#include
"khello.h"</FONT></SPAN></DIV>
<DIV><FONT face=Verdana size=2></FONT> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>int main( int
argc, char **argv )<BR>{<BR> KApplication a( argc, argv, "khello"
);<BR> KHello *w = new KHello();<BR>
w->setGeometry(100,100,200,100);</FONT></SPAN></DIV>
<DIV><FONT face=Verdana size=2></FONT> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>
a.setMainWidget( w );<BR> w->show();<BR> return
a.exec();<BR>}<BR>-------------khello.h-----------------------
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>#include
<kapp.h><BR>#include <kmainwindow.h><BR>#include
<kmessagebox.h><BR>#include <qpushbutton.h><BR>#include
<kmenubar.h><BR>#include <kpopupmenu.h></FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>class KHello :
public KMainWindow<BR>{<BR> Q_OBJECT<BR>public:<BR>
KHello();<BR> void closeEvent(QCloseEvent *);<BR>public slots:<BR>
void slotHello();<BR> void slotExit();<BR>private:<BR> QPushButton
*btnHello;<BR> QPushButton *btnExit;<BR> KMenuBar *menu;<BR>
KPopupMenu *file,
*help;<BR>};<BR></FONT></SPAN>------------khello.cpp---------------------</FONT></SPAN></DIV></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>#include
"khello.moc"<BR>#include <kmessagebox.h></FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>KHello::KHello() :
KMainWindow()<BR>{<BR> btnHello = new QPushButton("Hello",
this);<BR> btnHello->setGeometry(45,30,50,25);<BR>
btnHello->show();<BR> connect(btnHello, SIGNAL(clicked()), this,
SLOT(slotHello()));</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2> btnExit =
new QPushButton("Exit", this);<BR>
btnExit->setGeometry(105,30,50,25);<BR> btnExit->show();<BR>
connect(btnExit, SIGNAL(clicked()), this, SLOT(slotExit()));</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2> file = new
KPopupMenu();<BR> file->insertItem("&Hello", this,
SLOT(slotHello()));<BR> file->insertItem("&Exit", this,
SLOT(slotExit()));<BR> <BR> help = helpMenu("KHello\nby Daniel
Marjamäki\nUpdated by David Leimbach");<BR> <BR> menu =
menuBar();<BR> menu->insertItem("&File", file);<BR>
menu->insertItem("&Help", help);<BR>}</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>void
KHello::closeEvent(QCloseEvent *e)<BR>{<BR> kapp->beep();<BR>
KMainWindow::closeEvent(e);<BR>}</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>void
KHello::slotHello()<BR>{<BR> KMessageBox::information(this, "Hello
World!", "Important");<BR>}</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>void
KHello::slotExit()<BR>{<BR> close();<BR>}<BR></FONT></SPAN><SPAN
class=320073310-31032004><FONT face=Verdana
size=2>---------------build2---------------------</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>c++ -c
-I$KDEDIR/include -I$QTDIR/include -fno-rtti main.cpp -o
main.o<BR>$QTDIR/bin/moc khello.h -o khello.moc<BR>c++ -c -I$KDEDIR/include
-I$QTDIR/include -fno-rtti khello.cpp -o khello.o<BR>c++ -L$KDEDIR/lib
-L$QTDIR/lib -lkdeui -lkdecore $QTDIRqt -ldl -o khello main.o
khello.o<BR>------------------------------------</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>I'm fairly
confident that the source code is right and its my build scripts that are
wrong.</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>Q1: Why does the
output files (hello.o etc) always have an \r appended to the
names?</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>The only thing in
my scripts that's different is that I've changed -qt to $QTDIRqt
since</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>ld couldn't find
qt. My understanding here is -L/blah says the compiler should look in /blah for
libraries and -lfoo says the library is called foo. At runtime my program
'knows' to load foo but doesn't know where foo resides. If, OTOH, I use
-l/blah/foo my program will expect to load foo from /blah -- the path is
hardcoded. </FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>Q2: On my machine
then (L/blah -lfoo) == (-l/blah/foo) ?</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>Q3: Am I talking
rubbish? :)</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>Could anyone
advise?</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana
size=2>Martin</FONT></SPAN></DIV></BODY></HTML>
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic