Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → Linux problem (gcc, specifically)
Linux problem (gcc, specifically)
2007-01-18, 3:48 AM #1
Apparently we're not using the technology forum anymore, so here goes.

I'm having problems compiling programs with gcc and math.h. Some of the functions from math.h work while others are unrecognized by the compiler. For example:
Code:
#include <stdio.h>
#include <math.h>

int main ()
{
	printf("%fd\n", exp(2));
	return 0;
}
Throws the error
Code:
/tmp/ccuY4Z73.o: In function `main':test.c:(.text+0x26): undefined reference to `exp'
at compile time.
However, if I change "exp(2)" to "pow(2,2)" everything works just fine.

Any ideas?
Ban Jin!
Nobody really needs work when you have awesome. - xhuxus
2007-01-18, 4:01 AM #2
http://www.faqs.org/faqs/C-faq/faq/

Could it be
Quote:
14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.

A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.

?
2007-01-18, 4:28 AM #3
That worked, thanks!

Though does anyone know what the "m" stands for?
Ban Jin!
Nobody really needs work when you have awesome. - xhuxus
2007-01-18, 5:41 AM #4
Originally posted by SMOCK!:
That worked, thanks!

Though does anyone know what the "m" stands for?

Math.
[This message has been edited. Deal with it.]
2007-01-18, 6:20 AM #5
... Oh. :ninja:
Ban Jin!
Nobody really needs work when you have awesome. - xhuxus
2007-01-18, 9:13 AM #6
You have to link to the math library yourself?? Laaaaamme.
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2007-01-18, 2:22 PM #7
Yeah, certain libraries require linking. One of my profs explained it once, but I can't remember what the reasoning was.
2007-01-18, 2:36 PM #8
It was probably some inane Linux-type thinking from someone like Linus Torvalds.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2007-01-18, 4:41 PM #9
Originally posted by Emon:
It was probably some inane Linux-type thinking from someone like Linus Torvalds.

Except for the fact that I have to do it in FreeBSD and Solaris as well.

The math library isn't contained within libc, so you have to link to it.
[This message has been edited. Deal with it.]

↑ Up to the top!