[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Hello World newbie woes
From:       Anne-Marie Mahfouf <annemarie.mahfouf () free ! fr>
Date:       2004-03-31 13:54:18
Message-ID: 200403310854.18454.annemarie.mahfouf () free ! fr
[Download RAW message or body]

On March 31, 2004 05:57 am, Martin Welch wrote:
> 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
 
>> 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