¿Por qué recibo el error "referencia indefinida a sqrt" aunque incluyo el encabezado math.h? [duplicar
Esta pregunta ya tiene una respuesta aquí:
referencia indefinida a sqrt (u otras funciones matemáticas) 4 respuestasSoy muy nuevo en C y tengo este código:
#include <stdio.h>
#include <math.h>
int main(void)
{
double x = 0.5;
double result = sqrt(x);
printf("The square root of %lf is %lf\n", x, result);
return 0;
}
Pero cuando compilo esto con:
gcc test.c -o test
Recibo un error como este:
/tmp/cc58XvyX.o: In function `main':
test.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status
¿Por qué pasó esto? Essqrt()
no en elmath.h
¿archivo de cabecera? Me sale el mismo error concosh
y otras funciones trigonométricas. ¿Por qué