Troubleshoot - Undefined Reference to Symbol `sqrt`

Published in the topic of C

Undefined Reference to Symbol sqrt

Error Stack

Trying to compile hand detection source code, hand.c.

abdillah@linux:opencv-hand-detection-master$ gcc hand.c -o hand `pkg-config --cflags --libs opencv`
/usr/bin/ld: /tmp/ccFh6ycB.o: undefined reference to symbol 'sqrt@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/ error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status


It happened because in the source, there is a call to sqrt() which the definition inside <math.h>. Therefore, math library not linked.


Add -lm to the argument compiler solve this.