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

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



On Sat, Nov 25, 2000 at 18:36:56 +0100, Viktor Rosenfeld wrote:
> 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 $ 

Add "-lm" to that line.

> When I looked into /usr/include/math.h there was no definition of
> sqrt().

<math.h> is the proper file to include for sqrt(). Internally, it includes
other header files, including the one that has the sqrt() prototype, but
as a user of the C library, you should not care about that.

> But I can't find any libm in dselect.

The library defining the math functions, libm, is a part of the libc6
package.

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

Your code looks fine, but your command line doesn't. Including the header
defining a prototype for a function is a different thing from linking your
object files against the library implementing that function. This
distinction is often hidden in other environments.

HTH,
Ray
-- 
Obsig: developing a new sig



Reply to: