在C中使用sqrtf():“对'sqrtf'的未定义引用" [英] Using sqrtf() in C: "undefined reference to `sqrtf'"

查看:645
本文介绍了在C中使用sqrtf():“对'sqrtf'的未定义引用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Linux, Ubuntu  12.04 (精确的穿山甲)和Geany进行编码.直到我使用sqrtf命令找到浮点数的平方根之前,我用C语言编写的代码都可以正常工作.

I am using Linux, Ubuntu 12.04 (Precise Pangolin), 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.

错误:HAC3.c :(.text + 0xfd7):未定义对"sqrtf"的引用.

Error: HAC3.c:(.text+0xfd7): undefined reference to `sqrtf' .

我在以下位置使用sqrtf()的代码部分:

The part of code I am using sqrtf() in:

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,但这似乎不是问题.

I included math.h, but this doesn't seem to be the problem.

有没有办法修复Geany,这样就不会再出现了?

Is there a way to fix Geany so this won't come up again?

推荐答案

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

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.

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

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

这篇关于在C中使用sqrtf():“对'sqrtf'的未定义引用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆