I am using Code::Blocks 20.03 on Linux. When I try to compile the following code using the Build (F9) function I get undefined reference to 'sqrt'
:
#include <stdio.h>
#include <math.h>
main() {
int a = 5;
float b = sqrt(a);
printf("%f", b);
}
When I put 5 in place of the a
in sqrt, the code compiles and runs. When I copy this code to an online compiler, it runs. When I manually gcc code.c -o code -lm
, the code runs.
I'm tempted to believe that the problem is with CodeBlocks, however, I also realise that I'm a newbie to programming and might not have set everything up right. What else could I try to be able to make conclusions here and hopefully to find a solution?