Build error "Undefined Reference to `sqrt' " in Atom editor

Asked

Viewed 1,327 times

0

This C code is not compiling in Atom, but in Codeblocks it 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
  • 1

    Try using text instead of images to describe your error. The way it was, your question wouldn’t go in the search for the site even if someone had the same problem in the future. Also, screen reader users could not help you.

  • 1

    Which compiler are you using ? What build flags ? Which command did you use to compile ? The error certainly in these points I asked. Here’s how I compiled and ran the program without problem -> https://i.stack.Imgur.com/Devxy.png

  • I don’t use Windows, and the gcc command on the terminal doesn’t work, the problem is that it doesn’t compile either in the terminal or in Atom when I use.

  • I was able to solve the problem, I used the -lm option in the editor’s build settings.

  • @Starlord Post a reply with details if you can.

  • Same solution, different function: https://answall.com/q/246122/64969 possible duplicate?

  • The solution to my problem was to use the '-lm' argument in the build command of the program, for example: $ gcc 'program name_do_program. c' -lm -o 'script name'

Show 2 more comments

1 answer

0

The problem is that you are including the library but are not passing the flag in gcc. Try setting the flag -lm, sort of like this

gcc main.c -o main -lm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.