LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 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: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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



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?? 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

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

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

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