在c中未定义的“sqrtf”引用。

时间:2022-11-21 05:30:12

Hello i am using linux 12.04 and geany for coding. The code i am writing in C worked completely fine until i used the sqrtf command to find the square root of a float. Error: HAC3.c:(.text+0xfd7): undefined reference to `sqrtf' .

你好,我正在使用linux 12.04和geany进行编码。我在C中编写的代码一直工作得很好,直到我使用sqrtf命令找到浮点数的平方根。错误:HAC3.c:(.text+0xfd7):未定义的“sqrtf”引用。

The part of code i am using sqrtf:

我使用sqrtf的部分代码:

float syn(float *a, float *b, int dimensions)
{
    float similarity=0;
    float sumup=0;
    float sumdown=0;
    float as=0;
    float bs=0;
    int i;
    for(i=0; i<dimensions; i++)
    {
        sumup = sumup + a[i] * b[i];
        as = as + a[i] * a[i];
        bs = bs + b[i] * b[i];
    }
    sumdown = sqrtf(as) * sqrtf(bs);
    similarity = sumup / sumdown;
    return similarity;
}

I included math.h but this doesn't seem to be the problem. So i am wondering is there any way to fix geany so this won't come up again? I've got little knowledge so try to explain if possible.

我包括数学。但这似乎不是问题所在。所以我在想有没有办法修复geany,这样就不会再出现了?我没有什么知识,所以尽量解释一下。

2 个解决方案

#1


7  

Go to Build -> Set Build Commands then under C commands click on the empty label and it will let you specify a new label (name it Link). Type in it gcc -Wall -o "%e" "%f" -lm - where -lm will tell it to link the math library to your app. Click OK.

Go to Build -> Set构建命令,然后在C命令下点击空标签,它会让你指定一个新的标签(名称链接)。输入gcc - wall -o "%e" "%f" -lm -lm将告诉它将数学库链接到你的应用程序。点击确定。

Then click on Build and select your newly created label - Link. This should do it for you.

然后单击Build并选择您新创建的标签链接。这应该为你做。

#2


7  

You need to link with -lm to provide the math functions.

您需要链接到-lm来提供数学函数。

#1


7  

Go to Build -> Set Build Commands then under C commands click on the empty label and it will let you specify a new label (name it Link). Type in it gcc -Wall -o "%e" "%f" -lm - where -lm will tell it to link the math library to your app. Click OK.

Go to Build -> Set构建命令,然后在C命令下点击空标签,它会让你指定一个新的标签(名称链接)。输入gcc - wall -o "%e" "%f" -lm -lm将告诉它将数学库链接到你的应用程序。点击确定。

Then click on Build and select your newly created label - Link. This should do it for you.

然后单击Build并选择您新创建的标签链接。这应该为你做。

#2


7  

You need to link with -lm to provide the math functions.

您需要链接到-lm来提供数学函数。