As in the comment out statement, there is no problem if you directly substitute a number, but if you insert a variable, you will get a compilation error.
What should I do?
running environment:
Ubuntu
gcc 9.3.0
compilation results:
$gccsqrtyou.c
/usr/bin/ld: /tmp/cc0MDw2q.o:in function `main':
sqrtyou.c: (.text+0x23): undefined reference to `sqrt'
collect2:error:ld returned1 exit status
source code:
sqrtyou.c
#include<stdio.h>
# include <math.h>
int main()
{
double first = 2.0;
double second;
second = sqrt(first);
// second = sqrt(2.0);
printf("%f\n", second);
}
Comments are included, but the sqrt() manual also includes
Link with -lm.
is described as .Read the documentation.
© 2024 OneMinuteCode. All rights reserved.