LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2003, 09:35 PM   #1
macro-linux
LQ Newbie
 
Registered: Sep 2003
Posts: 25

Rep: Reputation: 15
complie under qt


I use the qt to programming,
but after the make
tell me that
Code:
g++  -o helloworld    -L/usr/lib/qt-3.1/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x18): In function `_start':
../sysdeps/i386/elf/start.S:77: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [helloworld] Error 1
why,my code is right!
 
Old 11-03-2003, 10:32 PM   #2
jhorvath
Member
 
Registered: Sep 2002
Location: OH, USA
Distribution: 2.6.16-1.2096_FC5 #1
Posts: 245

Rep: Reputation: 30
upon reading your output ...you specify for g++ to output 'helloworld' via the '-o helloworld'...but you do not specify the source files... ie `g++ -o helloworld helloworld.cc ...`

your code could be god sent....but if the compiler doesn't know what to compile your program from ...it won't work too well.. :)...

Last edited by jhorvath; 11-03-2003 at 10:45 PM.
 
Old 11-04-2003, 12:54 AM   #3
macro-linux
LQ Newbie
 
Registered: Sep 2003
Posts: 25

Original Poster
Rep: Reputation: 15
this code is from the KDE/Qt,
it is a example!
my some code is that wrong,but I can't understand what is wrong
one:qmake make the makefile
two:make
I don't understand what I am wrong,help me!
there is no information about the Qt,
introduce some information to me!
thanks !
 
Old 11-04-2003, 11:16 AM   #4
jhorvath
Member
 
Registered: Sep 2002
Location: OH, USA
Distribution: 2.6.16-1.2096_FC5 #1
Posts: 245

Rep: Reputation: 30
..? you got me bro...?

all i'm saying is that in that line

g++ -o helloworld -L/usr/lib/qt-3.1/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm

there is no source file listed there to compile...
you ran this from a pre-made makefile ? if so ..post the make file..
irregardless ...go to the directory where this 'makefile' is and check to see if there is a file called 'helloworld.cc' or 'helloworld.cpp' ...etc then run this ::

g++ -o helloworld helloworld.cc -L/usr/lib/qt-3.1/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm

...above where you see the 'helloworld.cc' ...change that to whatever the helloworld source file is called....
 
Old 11-04-2003, 06:59 PM   #5
macro-linux
LQ Newbie
 
Registered: Sep 2003
Posts: 25

Original Poster
Rep: Reputation: 15
helloworld.pro code
Code:
unix {
  UI_DIR = .ui
  MOC_DIR = .moc
  OBJECTS_DIR = .obj
}
TEMPLATE	=app
CONFIG	+= qt warn_on release
LANGUAGE	= C++
helloworld.ui.h code
Code:
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
/* helloworld.cpp */
#include <qapplication.h>
#include <qlabel.h>
#include <qstring.h>

int main( int argc, char **argv)
{
    QApplication app(argc,argv);
    QLable *label = new QLabel(NULL);
    QString string ("Hello, world");
    label->setText(string);
    label->setAlignment( Qt:AlignVCenter | Qt::AlignHCenter);
    label->setGeometry(0,0,180,75);
    label->show();
    app.setMainWidget(label);
    return (app.exec());
}
I am first use the qt programming
thank you jhorvath!
 
Old 11-04-2003, 07:13 PM   #6
jhorvath
Member
 
Registered: Sep 2002
Location: OH, USA
Distribution: 2.6.16-1.2096_FC5 #1
Posts: 245

Rep: Reputation: 30
okay...let's try this

..first off , there are 2 syntax errors in your code ...
Code:
/* helloworld.cpp */
#include <qapplication.h>
#include <qlabel.h>
#include <qstring.h>

int main( int argc, char **argv)
{
    QApplication app(argc,argv);
    QLabel *label = new QLabel(NULL);  // this was wrong, it is correct now
    QString string ("Hello, world");
    label->setText(string);
    label->setAlignment( Qt::AlignVCenter | Qt::AlignHCenter); // this was wrong, it is correct now
    label->setGeometry(0,0,180,75);
    label->show();
    app.setMainWidget(label);
    return (app.exec());
}
...let's go and try to build this and see if that is better , k
..don't forget to tell the compiler what source to build ...on my system ...i did this
[saved the code you see above as 'helloworld.cc']
[and i compiled with] `g++ -Wall -o helloworld helloworld.cc -L/usr/lib/qt/lib -lqt`

fin
 
Old 11-04-2003, 10:00 PM   #7
macro-linux
LQ Newbie
 
Registered: Sep 2003
Posts: 25

Original Poster
Rep: Reputation: 15
thanks!
I first creat a new helloworld.pro
and creat a helloworld.ui.h.
add the code putin the helloworld.ui.h
then use the command qmake -o makefile helloworld.pro to
creat the makefile,and use the command make,
and occure the top wrong,I have revised my code,but the wrong is all the stay!Under the qt I havn't see the postfix .cc,so^
it is me so foolish,my some code occure the same wrong,
underfine the "main",
 
Old 11-04-2003, 10:26 PM   #8
jhorvath
Member
 
Registered: Sep 2002
Location: OH, USA
Distribution: 2.6.16-1.2096_FC5 #1
Posts: 245

Rep: Reputation: 30
no sir...

just for simplicities sake..and for this example ...just save that code i fixed ...(copy/paste)..into a file and call it "helloworld.cpp"

then ...when you are in the directory where you saved 'helloworld.cpp' type in :

g++ -Wall -o helloworld helloworld.cpp -L/usr/lib/qt/lib -lqt

..then if no errors, type

./helloworld

no MAKE , no QMAKE, just what i said :) ...for now
 
Old 11-05-2003, 12:28 AM   #9
macro-linux
LQ Newbie
 
Registered: Sep 2003
Posts: 25

Original Poster
Rep: Reputation: 15
oh!no
my code is under the qt.if use your mothod,
the complie don't know the head file
for example <qapplicatioon.h>
 
Old 11-05-2003, 05:41 AM   #10
mr_segfault
Member
 
Registered: Oct 2003
Location: Australia
Distribution: Redhat 9
Posts: 95

Rep: Reputation: 15
Hmm seems that there is some confusion here...

First of, lets forget about any possible errors in your code, cover them if you get a compiler error which indicates that there is a problem in your source code (notice, no reference to your source file in the error message generated, ie your source file will be something like helloworld.cpp.)

Next, this is the build line that qmake generated automatically for you from your .pro file:

g++ -o helloworld -L/usr/lib/qt-3.1/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm

Ok, now this is what it should look like:

g++ -o helloworld helloworld.cpp -L/usr/lib/qt-3.1/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm

If you run the live above, it will most probably compile your code (since now it knows what the source file is)

So I guess that in your .pro file there is a mistake or missing option, one which specifies which .cpp files are to be included in your build.

Ok, so I quickly googled for 'qmake .pro' and the fourth hit down will give you the answer.

I think the line :

SOURCES = helloworld.cpp

should be added to your .pro

And if you have a helloworld.h header also add

HEADERS = helloworld.h

That line is for dependancy checking, used to determine if it needs to compile this unit (ie if either source or header is changed). This is not used to build the code, instead it is used by make to fire a rule cause it to rebuild your code.

I dont not have experience with qmake, so I could be wrong, but that is how it looks to me.


Good luck..
 
Old 11-06-2003, 05:18 AM   #11
macro-linux
LQ Newbie
 
Registered: Sep 2003
Posts: 25

Original Poster
Rep: Reputation: 15
thank you!
I am successful in the programme!but the other in the same
mothod,can't successful!shit!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to complie php with imap shitoryu Linux - Software 0 08-16-2005 09:02 AM
help! ahout complie the modules tyler28 Programming 1 06-24-2005 10:57 PM
QT3,use from CD or complie myself? ngan_yine Mandriva 0 01-14-2004 08:13 AM
I had a error during kernel complie.. what should I do..?? HeyJude Linux - General 2 09-09-2003 05:21 AM
kernel complie error DMRansom Linux - Newbie 3 06-09-2003 08:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration