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

Where is the sqrt() function in glibc? What is libm?



Hi folks,

I'm trying to learn C using the K&R book.  I wrote the following code to
test something they are mentioning in chapter 2.7, but I can't compile
it.

	#include <stdio.h>
	#include <math.h>

	int main(int argc, char argv[])
	{
		int i = 4;
		printf("Int: %f, Double: %f\n", sqrt(i), sqrt((double) i));
		return 0;
	}

This is the output I get by gcc:

	18:29 viktor@bart:~/Projekte/c/2 $ gcc -o test test.c
	/tmp/ccc01936: In function `main':
	/tmp/ccc01936(.text+0x17): undefined reference to `sqrt'
	/tmp/ccc01936(.text+0x2e): undefined reference to `sqrt'
	18:30 viktor@bart:~/Projekte/c/2 $ 

When I looked into /usr/include/math.h there was no definition of
sqrt().  Instead there were some constants defined such as:

	#define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi)
*/                

I looked into /usr/doc/libc6-dev/changelog.gz and there is the entry:

	1997-03-04 19:14  Andreas Schwab 
<schwab@issan.informatik.uni-dortmund.de>
	
		* sysdeps/m68k/fpu/__math.h: Update feature tests.
		(fabs): Remove defininition, it is a gcc builtin.
		(sqrt, __sqrt): Remove definition, they have wrappers in libm.

But I can't find any libm in dselect.  This is still on a slink machine,
I haven't come around to upgrading to potato yet.

Anybody who can help me, getting sqrt() to work?  Or is my code
incorrect?

TIA,
Viktor
-- 
Viktor Rosenfeld
E-Mail:		mailto:rosenfel@informatik.hu-berlin.de
HertzSCHLAG:	http://www.informatik.hu-berlin.de/~rosenfel/hs/



Reply to: