Skip to content

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

Closed
@ohuf

Description

@ohuf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions