linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* undefined sqrt()
@ 2002-10-24 20:06 Theo. Sean Schulze
  2002-10-24 20:17 ` Karthik Vishwanath
  2002-10-24 20:28 ` Steven Smith
  0 siblings, 2 replies; 9+ messages in thread
From: Theo. Sean Schulze @ 2002-10-24 20:06 UTC (permalink / raw)
  To: linux-c-programming; +Cc: tschulze

Hello,

This is a real newbie type question.  Usually my problems with C involve pointers, but this one is a problem with the function sqrt().  I had a math problem I needed to solve, and having forgotten my high school algebra about 25 years ago, I thought I could quickly write a C program to get an approximate answer by brute force.  This program is supposed to figure out one of the sides of a right triangle using the other side and the hypotenuse.  The hypotenuse has a fixed relationship to the side of unknown lenght.  Anyway, here is the code, such as it is:


//
// Filename: glide.c
// Version: 0.0.1     Date: 24 October, 2002
//
// Author: T. Sean Schulze
// System: i386-slackware-linux-gnu
//
// Purpose: The purpose of this script is to use brute force to find out
// how long the long side and the hypotenuse of a right triangle are 
// when the short side of the triangle is 35 feet long.  This will, of 
// course, vary depending on the angle between the two unknown sides.
//
// Limitations: Down and dirty.  Not useful for much else than this brute
// attempt.

#include <stdio.h>
#include <math.h>
#include <float.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

double a ;
double b ;
double c ;
double GLIDE ;

int
main(void) /*(int argc, char **argv)*/
{
	GLIDE = 0.012 ;
	a = 0.0 ;

	while( b < 35.0 ) 
	{
		a++ ;
		c = a * (1 + GLIDE) ;
		b = sqrt((c * c) - (a * a)) ;

	}
	
	printf("Glide = %f\n", GLIDE);
	printf("a = %f\n", a) ;
	printf("b = %f\n", b) ;
	printf("c = %f\n", c) ;

	exit(0);

}

When I try to compile it, I get these messages:

dragoon:/home/tschulze/bin # gcc -Wall -o glide glide.c
/tmp/ccXahjXY.o: In function `main':
/tmp/ccXahjXY.o(.text+0x98): undefined reference to `sqrt'
collect2: ld returned 1 exit status

Could someone please give me a hint why this doesn't work?

TIA,
Sean

-- 
Theo. Sean Schulze
tschulze@teamfinders.org

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: undefined sqrt()
@ 2002-10-26 10:07 Ruslan U. Zakirov
  0 siblings, 0 replies; 9+ messages in thread
From: Ruslan U. Zakirov @ 2002-10-26 10:07 UTC (permalink / raw)
  To: linux-c-programming

TSS> Glynn,
TSS> Thanks for the explanation.  I understand now.  After getting your explanation, I did a bit of web browsing to try to find a page that tells me what libraries I need for which header files, but
TSS> I haven't been too successful.  Do you know of a URL where I could find that info?
TSS> Thanks,
TSS> Sean
Hello!
There are two sections in man sqrt.
1) Library: In this section described which library you must link with
your program.
2) Sinopsis: Here specified file where you can find prototype of
function. This file(s) you must include in your project.
Good luck.
_______________________________________________________________________
Sorry for my English.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-10-26 10:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-24 20:06 undefined sqrt() Theo. Sean Schulze
2002-10-24 20:17 ` Karthik Vishwanath
2002-10-24 20:50   ` Theo. Sean Schulze
2002-10-24 21:50     ` Karthik Vishwanath
2002-10-25  8:17     ` Glynn Clements
2002-10-25 17:27       ` Theo. Sean Schulze
2002-10-25 19:29         ` Glynn Clements
2002-10-24 20:28 ` Steven Smith
  -- strict thread matches above, loose matches on Subject: below --
2002-10-26 10:07 Ruslan U. Zakirov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).