gpt4 book ai didi

c - 在 C : "undefined reference to ` sqrtf'"中使用 sqrtf()

转载 作者:IT王子 更新时间:2023-10-28 23:58:12 25 4
gpt4 key购买 nike

我正在使用 Linux,Ubuntu 12.04 (Precise Pangolin),以及用于编码的 Geany。在我使用 sqrtf 命令求 float 的平方根之前,我用 C 编写的代码工作得很好。

Error: HAC3.c:(.text+0xfd7): undefined reference to `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;
}

我包含了 math.h,但这似乎不是问题所在。

有没有办法修复 Geany,使其不再出现?

最佳答案

转到 Build -> Set Build Commands 然后在 C commands 下单击空标签,它会让您指定一个新标签(将其命名为 Link)。输入 gcc -Wall -o "%e""%f"-lm - 其中 -lm 将告诉它链接 math库到您的应用程序。单击确定

然后单击Build 并选择您新创建的标签 - Link。这应该为您完成。

关于c - 在 C : "undefined reference to ` sqrtf'"中使用 sqrtf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16974669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com