squancy / stl-parser

Convert between ASCII and binary STL files, calculate volume, surface area and estimated price for 3D printing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'make' error: "undefined reference to 'sqrt'"

ohuf opened this issue · comments

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.

Thanks for pointing this out! I will update the Makefile accordingly.