[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>&nbsp;</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>&nbsp;</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 
&lt;kapp.h&gt;<BR>#include &lt;kmainwindow.h&gt;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>int main( int 
argc, char **argv )<BR>{<BR>&nbsp; KApplication a( argc, argv, "khello" 
);<BR>&nbsp; KMainWindow *w = new KMainWindow();<BR>&nbsp; 
w-&gt;setGeometry(100,100,200,100);</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>&nbsp; 
a.setMainWidget( w );<BR>&nbsp; w-&gt;show();<BR>&nbsp; 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>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>int main( int 
argc, char **argv )<BR>{<BR>&nbsp; KApplication a( argc, argv, "khello" 
);<BR>&nbsp; KHello *w = new KHello();<BR>&nbsp; 
w-&gt;setGeometry(100,100,200,100);</FONT></SPAN></DIV>
<DIV><FONT face=Verdana size=2></FONT>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>&nbsp; 
a.setMainWidget( w );<BR>&nbsp; w-&gt;show();<BR>&nbsp; return 
a.exec();<BR>}<BR>-------------khello.h-----------------------
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>#include 
&lt;kapp.h&gt;<BR>#include &lt;kmainwindow.h&gt;<BR>#include 
&lt;kmessagebox.h&gt;<BR>#include &lt;qpushbutton.h&gt;<BR>#include 
&lt;kmenubar.h&gt;<BR>#include &lt;kpopupmenu.h&gt;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>class KHello : 
public KMainWindow<BR>{<BR>&nbsp; Q_OBJECT<BR>public:<BR>&nbsp; 
KHello();<BR>&nbsp; void closeEvent(QCloseEvent *);<BR>public slots:<BR>&nbsp; 
void slotHello();<BR>&nbsp; void slotExit();<BR>private:<BR>&nbsp; QPushButton 
*btnHello;<BR>&nbsp; QPushButton *btnExit;<BR>&nbsp; KMenuBar *menu;<BR>&nbsp; 
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 &lt;kmessagebox.h&gt;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>KHello::KHello() : 
KMainWindow()<BR>{<BR>&nbsp; btnHello = new QPushButton("Hello", 
this);<BR>&nbsp; btnHello-&gt;setGeometry(45,30,50,25);<BR>&nbsp; 
btnHello-&gt;show();<BR>&nbsp; connect(btnHello, SIGNAL(clicked()), this, 
SLOT(slotHello()));</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>&nbsp; btnExit = 
new QPushButton("Exit", this);<BR>&nbsp; 
btnExit-&gt;setGeometry(105,30,50,25);<BR>&nbsp; btnExit-&gt;show();<BR>&nbsp; 
connect(btnExit, SIGNAL(clicked()), this, SLOT(slotExit()));</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>&nbsp; file = new 
KPopupMenu();<BR>&nbsp; file-&gt;insertItem("&amp;Hello", this, 
SLOT(slotHello()));<BR>&nbsp; file-&gt;insertItem("&amp;Exit", this, 
SLOT(slotExit()));<BR>&nbsp; <BR>&nbsp; help = helpMenu("KHello\nby Daniel 
Marjamäki\nUpdated by David Leimbach");<BR>&nbsp; <BR>&nbsp; menu = 
menuBar();<BR>&nbsp; menu-&gt;insertItem("&amp;File", file);<BR>&nbsp; 
menu-&gt;insertItem("&amp;Help", help);<BR>}</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>void 
KHello::closeEvent(QCloseEvent *e)<BR>{<BR>&nbsp; kapp-&gt;beep();<BR>&nbsp; 
KMainWindow::closeEvent(e);<BR>}</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>void 
KHello::slotHello()<BR>{<BR>&nbsp; KMessageBox::information(this, "Hello 
World!", "Important");<BR>}</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=320073310-31032004><FONT face=Verdana size=2>void 
KHello::slotExit()<BR>{<BR>&nbsp; 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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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