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"
Asked
Active
Viewed 521 times
-2
-
Please show your compilation statement. – Sourav Ghosh Apr 23 '18 at 05:46
1 Answers
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
.
-
1
-
-
@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