This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Trying to learn C on the gcc compiler


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" );
	else
	 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]