Re: [Anjuta-list] Error: undefined reference to cos even after including math.h in the C Program



On Sat, 2003-04-05 at 06:16, Jnanesh wrote:
> 	I am using GNU Compliler gcc 3.2 on Red Hat Linux. When I build the C
> program given below after compiling
> 
> 	/* Created by Anjuta version 1.0.1 */
> 	/*	This file will not be overwritten */
> 	#include <stdio.h>
> 	#include <math.h>
> 	#define pi 3.1415
> 	int main()
> 	{
> 		double a;
> 		a=sin(pi/2);
> 		printf("a = %lf",a);
> 		return(0);
> 	}
> 
> It gives the error as 
> 	main.c:9: undefined reference to sin
> 
> Please help to overcome this problem
> 
You need to link the library also. To link with the library during
build, go to Settings->Compiler and linker options->Libraries and add
"m" (for libm.a). Build your program again and it should link fine now.

Regards,
-Naba






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]