Sqrtf undefined reference to `sqrtf 'in c

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

Part of the code in which I am using 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 have included math.h, but that does not seem to be the problem. So I am wondering if there is a way to fix geany so that it does not appear again? I have little knowledge, so try to explain, if possible.

+8
c linux geany
source share
2 answers

Go to Build Set Build Commands , then in C commands click on an empty shortcut and it will allow you to specify a new shortcut (name it Link ). Enter it gcc -Wall -o "%e" "%f" -lm - where -lm will tell it to link the math library to your application. Click OK .

Then click Build and select the new shortcut created - Link . That should do it for you.

+7
source share

You need to associate with -lm to provide math functions.

+7
source share

All Articles