Trying to learn C on the gcc compiler

Kelly Schauf
Mon Jun 5 06:39:00 GMT 2000

To the forum:

I have been using the gcc compiler as a tool for learning C, and I am
having problems compiling the following simple program:

#include <stdio.h>
#include <stdlib.h>
#include <math.h> /* Include file for sqrt ()  */

int main( void )
	double num;

	printf( "Enter a non negative number: " );
	/*  The %lf conversion specifier indicates a 
	*data object of type double
	scanf( "%lf", &num);
	if (num < 0)
	 printf( "Input Error: Number is negative.\n" );
	 printf( "The Square root is: %f\n", sqrt( num ));
	exit( 0 );

The error that I get is "undefined reference to sqrt".  

Any ideas?  Thanks in advance.

Kelly Schauf

More information about the Gcc mailing list