Using sqrtf() in C: "undefined reference to `sqrtf'"
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
.
Then click on Build
and select your newly created label - Link
. This should do it for you.
In addition to the many fine answers here, the portable form of the command that supports C99 version of <math.h>
is specified by POSIX as c99 -l m
. That having been said, every important Linux compiler supports -lm
.
You need to link with -lm
to provide the math functions.