簡體   English   中英

這個錯誤是什么意思?

[英]What does this error mean?

/tmp/ccjiJKv2.o:在 function func':
b.c:(.text+0x16b): undefined reference to
func':
b.c:(.text+0x16b): undefined reference to
func':
b.c:(.text+0x16b): undefined reference to

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) ;

}

您沒有鏈接包含 sqrt實現的庫。

該庫稱為“libm”(數學庫),可以按如下方式鏈接:

gcc -o myprog infile.c -lm
#include <math.h> - is this what you need?

此外, Link with -lm

你必須鏈接數學庫。 -lm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM