Что означает эта ошибка? - PullRequest
3 голосов
/ 12 августа 2011

/ tmp / ccjiJKv2.o: в функции func':<br> b.c:(.text+0x16b): undefined reference to sqrt '
collect2: ld вернул 1 статус выхода

Вот код, и я использую компилятор gcc ..

/*Write a function that receive 5 integers and returns the sum,average and standard deviation of these numbers*/

/*Author:Udit Gupta     Date:10/08/2011*/

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

void func (int *,float *,float *);

int main () {

        float avg,std_dev;

        int sum;

        func (&sum,&avg,&std_dev);      /*Passing address of variables where output will be stored.....*/

        printf ("The sum of numbers is %d\n",sum);
        printf ("The average of numbers is %f\n",avg);
        printf ("The standard deviation of numbers is %f\n",std_dev);

}


void func (int *sum_, float *avg_ , float * std_dev_) {

        int n1,n2,n3,n4,n5;

        printf("Please enter the number:");
                scanf("%d%d%d%d%d",&n1,&n2,&n3,&n4,&n5);


        /*Formula for sum,average and standard deviation*/

        *sum_ = n1+n2+n3+n4+n5;                 /*Writing output at the address specified by arguments of function*/
        *avg_ = *sum_ / 5 ;
        *std_dev_ = sqrt ( pow((n1-*avg_),2)+pow((n2-*avg_),2)+pow ((n3-*avg_),2)+pow ((n4-*avg_),2)+pow ((n5-*avg_),2)/4) ;

}

Ответы [ 3 ]

5 голосов
/ 12 августа 2011

Вы не связываете библиотеку, которая содержит реализацию sqrt.

Эта библиотека известна как "libm" (математическая библиотека) и может быть связана со следующим:

gcc -o myprog infile.c -lm
3 голосов
/ 12 августа 2011
#include <math.h> - is this what you need?

Также Link with -lm

2 голосов
/ 12 августа 2011

Вы должны связать математическую библиотеку.-lm

...