AMD and math.h problems

AMD and math.h problems

Post by James M. Bl » Thu, 16 Nov 1995 04:00:00



Hi everyone,

Here's an interesting little error that I keep getting when I attempt to use
any of the functions in math.h.

 gcc PA.c
/tmp/cca002881.o(.text+0x1fd): undefined reference to `sqrt'

My machine is a AMD 486DX4/120.  However, when I attempt to compile the program
on my friend's Pentium 90, everything works fine.

Any idea as to if the chip makes a difference?

-Jim

PS, here's the program.

/* pi.c */

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

#define MAXNUMBER 1000

int kase = 0;

int numberOfValues;
int value[MAXNUMBER];

int totalPairs;
int pairsWithNoCommonFactor;

float pi;

int gcd ( int m, int n )
{
 if ( n <= m && m % n == 0 ) return n;
 else if ( m < n ) return gcd ( n, m );
 else return gcd ( n, m % n );

Quote:}

int main ( int argc, char ** argv )
{
 int i, j;

 while(1)
 {
  scanf("%d", &numberOfValues );
  if ( numberOfValues == 0 ) break;

  for(i=0;i<numberOfValues;i++)
    scanf("%d", &value[i]);

  kase++;
 {
  scanf("%d", &numberOfValues );
  if ( numberOfValues == 0 ) break;

  for(i=0;i<numberOfValues;i++)
    scanf("%d", &value[i]);

  kase++;

  /*
  printf("Case %d:\n", kase);
  */

  totalPairs = 0;
  pairsWithNoCommonFactor = 0;

  for(i=0;i<numberOfValues-1;i++)
   for(j=i+1;j<numberOfValues;j++)
   {
    totalPairs++;
    if ( gcd ( value[i], value[j] ) == 1 )
      pairsWithNoCommonFactor++;
   }

  if ( pairsWithNoCommonFactor == 0 )
    printf("No estimate for this data set.\n");
  else
  {
   pi = sqrt ( (6.0/(float)pairsWithNoCommonFactor)*(float)totalPairs );
   printf("%f\n", pi);
  }

  /*
  printf(" NCF = %d  Total = %d\n",
    pairsWithNoCommonFactor, totalPairs );
  printf(" Pi ~ %lf\n", pi);
  */
 }

Quote:}

--
===============================================================================
James M. Blum                                           Home: (810)737-9001
Merit Network, Inc.                                     Work: (313)936-0390
4251 Plymouth Rd., Suite C
Ann Arbor, MI 48105-2785
 
 
 

AMD and math.h problems

Post by Joseph Vigne » Thu, 16 Nov 1995 04:00:00




Quote:

> gcc PA.c
>/tmp/cca002881.o(.text+0x1fd): undefined reference to `sqrt'

Remember to include your math libraries:

gcc -o app app.o -lm
--


 
 
 

AMD and math.h problems

Post by robertson jason vi » Thu, 16 Nov 1995 04:00:00



Quote:>Hi everyone,

>Here's an interesting little error that I keep getting when I attempt to use
>any of the functions in math.h.

> gcc PA.c
>/tmp/cca002881.o(.text+0x1fd): undefined reference to `sqrt'

>My machine is a AMD 486DX4/120.  However, when I attempt to compile the program
>on my friend's Pentium 90, everything works fine.

Stupid question, but you did add -lm to the compilation flags, right?

Anyway, no, a math coprocessor problem wouldn't cause that error (unless it
was a full moon, and all the stars were aligned right, and then a stray gamma
ray struck your computer.)
--
Buh?