'make' error: "undefined reference to 'sqrt'"
ohuf opened this issue · comments
Oliver Huf commented
Running 'make' with gcc in WSL, I get me the following error:
gcc main.o conv.o calc.o price.o helpers.o -o stlp
/usr/bin/ld: calc.o: in function 'surfArea':
calc.c:(.text+0x4f8): undefined reference to 'sqrt'
collect2: error: ld returned 1 exit status
make: *** [Makefile:2: stlp] Error 1
culprit seems to be gcc's standard behaviour of not including the math libraries (separate library 'libm').
I was able to fix this by linking it with -lm
in the Makefile:
Changing line 2 of Makefile
from..
gcc main.o conv.o calc.o price.o helpers.o -o stlp
to:
gcc main.o conv.o calc.o price.o helpers.o -o stlp -lm
fixes this for me.
Mark Frankli commented
Thanks for pointing this out! I will update the Makefile
accordingly.