LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   emacs 77: undefined reference to `main' (https://www.linuxquestions.org/questions/programming-9/emacs-77-undefined-reference-to-%60main-92356/)

creznedmick 09-13-2003 10:06 AM

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]

Hko 09-13-2003 11:56 AM

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...)

creznedmick 09-16-2003 07:46 PM

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


All times are GMT -5. The time now is 12:46 PM.