Compile error "undefined reference to 'sqrt'" in Atom editor

0

This code in C is not compiling on Atom, but CodeBlocks is working normally.

#include <stdio.h>
#include <math.h>

int main(){
    int a, b, hipotenusa, catetos;

    printf("A: ");
    scanf("%d", &a);

    printf("B: ");
    scanf("%d", &b);

    catetos = (a * a) + (b * b);

    hipotenusa = sqrt(catetos);

    printf("Hipotenusa = %d", hipotenusa);

    return 0;
}

Error:

 gcc-make-run: Compile Error

 /tmp/cc4PjTLW.o: in function 'main':
 capitulo13.c(.text+0x86): undefined reference to 'sqrt'
 collect2: error: ld return 1 exit status
    
asked by anonymous 14.10.2017 / 07:13

1 answer

0

The problem is that you are including the library but you are not passing the flag in gcc. Try to put the flag -lm , more or less so

gcc main.c -o main -lm
    
06.11.2018 / 14:02