Subject: Re: MATH.H
To: Harrison, Shawn <shawn_harrison@tyndale.com>
From: Allen Briggs <briggs@puma.macbsd.com>
List: port-mac68k
Date: 09/26/1997 09:58:15
> I have recently set MacBSD up on my SE/30, and have begun programming in 
> C. For the most part, the system is great and C is great, but I'm having 
> a problem with math.h. When I put the following at the beginning of the 
> program:
> 
> 	#include <stdio.h>
> 	#include <math.h>
> 
> The compiler apparently does not include the math functions. When I try 
> to use a math function, such as sqrt(), I get a message like the 
> following:
> 
> 	var/tmp/cc0002091.o: Undefined symbol '_sqrt' referenced from text 
> segment

Ah.  The "#include <math.h>" includes the file /usr/include/math.h
(which may, in turn, include others).  This doesn't include the
functions--just declarations.  To include the math library, you
also need to add -lm to the link line:

% cc -c hello.c
% cc -o hello hello.o -lm

or

% cc -o hello hello.c -lm

-allen

-- 
              Allen Briggs - end killing - briggs@macbsd.com