LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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
 
LinkBack Search this Thread
Old 09-13-2003, 10:06 AM   #1
creznedmick
Member
 
Registered: Jul 2003
Location: Austarlia
Distribution: redhat 7.3 & 9, Mandrake
Posts: 39

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


Good`aye
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
Michael

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



THE IMPLEMENTATION FILE
********************************************************************/
#include "myMath.h"

int length(int i)
{

}

doublele areaOfCircle(double r)
{

}

AND THE HEADER
****************************************************/
#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.


ERROR
/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
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

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

Quote:
Originally posted by creznedmick
[...]compile a library file [...]
[..snip..]
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.

Use:

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
creznedmick
Member
 
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
Michael
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting undefined reference to main error?? Mistro116@yahoo.com 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


All times are GMT -5. The time now is 03:33 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration