Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-13-2003, 10:06 AM   #1
Registered: Jul 2003
Location: Austarlia
Distribution: redhat 7.3 & 9, Mandrake
Posts: 39

Rep: Reputation: 15
emacs 77: undefined reference to `main'

I am a student trying to compile a library file in emacs and get this error message. I can`t for the life of me see what is obviously an obvious error.
Any help appreciated

the compile line I used is :
g++ myMath.cpp -Wall -o myMath

#include "myMath.h"

int length(int i)


doublele areaOfCircle(double r)


#include <cmath>

const double PI = 3.14159;

int length(int i); // length of integer i
double areaOfCircle(double r); // area of a circle with radius r.

/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

Compilation exited abnormally with code 1 at Sun Sep 14 00:50:13[/I]
Old 09-13-2003, 11:56 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Re: emacs 77: undefined reference to `main'

Originally posted by creznedmick
[...]compile a library file [...]
the compile line I used is :
g++ myMath.cpp -Wall -o myMath
You are trying to link the object file as well with this command line. As there's no main() function because it's a library, this will fail.


gcc -Wall -c -o myMath.o myMath.c

After that, you can convert it to a static library with:

ar crv libmyMath.a myMath.o

After this you can use it with gcc's "-l myMath" (and "-L /directory/of/your/libmyMath)" option to use it in programs.

(for dynamic libs I don't know...)
Old 09-16-2003, 07:46 PM   #3
Registered: Jul 2003
Location: Austarlia
Distribution: redhat 7.3 & 9, Mandrake
Posts: 39

Original Poster
Rep: Reputation: 15
re:emacs 77: undefined reference to `main'

Goodàye Hko
please excuse the tardiness of this reply. Thanks for your help, you helped clear up a missunderstanding of the use oc -c.
Thanks again


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Getting undefined reference to main error?? Programming 14 07-29-2011 08:28 AM
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
: undefined reference to `ceil' hubabuba Programming 7 02-26-2005 11:50 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:22 PM.

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