Click to See Complete Forum and Search --> : Help compiling my first Linux program..


Shawn Curry
12-12-2002, 07:04 PM
I'm used to MSVC++ and Borland C++ Builder, so I really dont have much experience running a command-line compiler.

I'm reading the tutorial for QT Designer, and it seemed a lot like C++ Builder. I made the first tutorial exercise - the Multiclip form clipboard manager thinggie.

It said to run qmake -o Makefile multiclip.pro to generate the makefile, and then it said to use make to build the Makefile.

The first time I ran make I picked up a couple of missing semicolons... but now I'm getting a different error and I dont know what it means / what I have to do about it.... Heres the output from make:



Thanks
[root@localhost multiclip]# qmake -o Makefile multiclip.pro
[root@localhost multiclip]# make
/usr/lib/qt3-gcc3.2/bin/uic multiclipform.ui -o .ui/multiclipform.h
/usr/lib/qt3-gcc3.2/bin/uic multiclipform.ui -i multiclipform.h -o .ui/multiclipform.cpp
g++ -c -pipe -Wall -W -I/usr/include/fontconfig -I/usr/include/Xft2 -O2 -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt3-gcc3.2/include -I.ui/ -I../multiclip -I.moc/ -I/usr/lib/qt3-gcc3.2/mkspecs/default -o .obj/multiclipform.o .ui/multiclipform.cpp
.ui/multiclipform.cpp:29: warning: `QPixmap uic_load_pixmap_MulticlipForm(const
QString&)' defined but not used
/usr/lib/qt3-gcc3.2/bin/moc .ui/multiclipform.h -o .moc/moc_multiclipform.cpp
g++ -c -pipe -Wall -W -I/usr/include/fontconfig -I/usr/include/Xft2 -O2 -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt3-gcc3.2/include -I.ui/ -I../multiclip -I.moc/ -I/usr/lib/qt3-gcc3.2/mkspecs/default -o .obj/moc_multiclipform.o .moc/moc_multiclipform.cpp
g++ -o multiclip .obj/multiclipform.o .obj/moc_multiclipform.o -L/usr/lib/qt3-gcc3.2/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o: In function `_start':
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [multiclip] Error 1

Shawn Curry
12-12-2002, 09:01 PM
would it help if i make a tarball an upload it to my website??

Shawn Curry
12-12-2002, 09:42 PM
Here it is (http://shawnsanswerpage.tripod.com/multclip.tar.gz) http://shawnsanswerpage.tripod.com/multclip.tar.gz

It's a QT project and 1 .ui file (plus all the generated files)

mdwatts
12-13-2002, 07:02 AM
I'll move this to the Programming forum in hopes one of our programming specialists can help.

truls
12-13-2002, 12:16 PM
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o:
In function `_start':
/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o(.text+0x18):
undefined reference to `main'

_start is part of the code that is added by gcc (I think), which in turn calls main(). You've got no main() function, so that's what the second line is saying.

Basically it's the linker telling you that it can't find a main() function. Qt-Designer does not add a main function, so you have to do this manually. There's an example on their web page, here (http://doc.trolltech.com/3.1/designer-manual-3.html) under the heading "Creating main.cpp" which should get you going.

Cheers.

Stuka
12-13-2002, 12:24 PM
You should be able to get this to compile by adding "main.o" to the Makefile, on the line that starts with "OBJECTS=" (without the quotes on both). Then run make again.

wapcaplet
12-13-2002, 12:39 PM
I can't seem to get at your tarball (Tripod refused me) but I would concur with Stuka and truls - it looks like you don't have a main() function.

I'm not familiar with qmake, but I have used a similar program called tmake (which also takes a project.pro file and turns it into a makefile). Rather than editing the makefile directly, you will probably want to edit your multiclip.pro file, and make sure that the file containing your main function (main.c or whatever) is part of the project.

Here's a .pro file from a project I did recently:

HEADERS = \
array.h \
bigraph.h \
debug.h \
edge.h \
hungarian.h \
label.h \
matrix.h \
maxmin.h \
msolver.h \
tableaux.h
SOURCES = \
bigraph.cpp \
debug.cpp \
edge.cpp \
hungarian.cpp \
matchdemo.cpp \ # <---- main() in here
maxmin.cpp \
msolver.cpp \
tableaux.cpp
TARGET = matchdemo # output program
TMAKE_CXXFLAGS = -Wall
CONFIG = debug


Most of the .cpp and all of the .h files listed above were different classes and stuff for my project. But matchdemo.cpp is what contains the main function, so you gotta make sure that's in there somewhere too.

And of course, as truls says, if you haven't written a main function yet, you'll need to do that first :)

If you still have trouble, you may want to try working strictly from the command line for a while, until you get more familiar with how programs are compiled. In my experience, it's actually a lot *easier*, at least for simple programs, to do it that way, rather than using a complex IDE like MSVC++ (which hides a lot of the compilation details from you). It took me several years of programming experience before I was comfortable with the concept of makefiles and stuff like that.

Keep at it and I'm sure you'll figure it out!

truls
12-13-2002, 01:37 PM
qmake creates the makefile from the project file.

Qt-designer does not create a main file by default, this must be done manually - all it does is create the application object and set the main widget and start the application. If you are using Qt-designer you should NOT edit the Makefile manually, just follow my instructions above. If you edit the Makefile you'll have to do it every time you add or remove a widget from the makefile and run qmake, so don't.

It won't make no sense editing the project file either, since these changes will be erased every time Qt-designer rewrites it's project file. If you are going to use a framework, work within the framework and you'll save yourself a lot of grief.

Of course, if you have designed everything to perfection in qt-designer, and THEN choose to add/remove files - knowing that you will never,ever, for as long as you live, use designer to change ANYTHING - you can do that editing the project file.

Stuka
12-13-2002, 02:25 PM
If that's the case, truls, then there must be some way in Designer to point qmake to your main function, because that's clearly what's missing (from the error message and reading the makefile).

wapcaplet
12-13-2002, 03:41 PM
truls - Thanks for the correction. I'm not familiar with Qt-designer, so I didn't know whether the .pro file was generated or hand-written.

Shawn Curry
12-13-2002, 03:50 PM
Yeah I got it.... I thought that's what it was trying to say..... I had created a main.cpp, but I didnt add it to the project :p

Cool :cool: