-2

I have a problem that when i compile a program whit pow or cos it be like: main':<br/>just-test.c:(.text+0x3d): undefined reference tosqrt' just-test.c:(.text+0x5e): undefined reference to 'pow' collect2: error: ld returned 1 exit status p.s: "im using linux and atom editor"

idleberg
  • 12,634
  • 7
  • 43
  • 70

1 Answers1

1

You don't need to download anything. But you have to tell the linker, that it should add the math library to your executable. Do this by adding -lm to the linker command line.

-l adds a library to linking, and the math library is simply called m.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • 1
    Ideally true, but you never know. :) – Sourav Ghosh Apr 23 '18 at 05:46
  • where do i add it ? – Mah Djaay Apr 23 '18 at 06:02
  • @MahDjaay: To the linker flags. Atom is really just an editor and not a fully blown IDE. So it really comes to the build system you're using. Are you using Makefiles, or CMake or SCons, or… ;there are hundreds of build systems, each with its own way do to this. However in the end, you just want to add that `-lm` to the linker command line. Like this. First compile `cc -c foobar.c` (generated `foobar.o`) then link (`cc -o foobar -lm foobar.o`). Rather sooner than later you have to learn about the steps that go into building the actual program binary, and not rely on some "IDE magic". – datenwolf Apr 23 '18 at 06:32