Friday, September 22, 2017

How ro get rid of the error : undefined reference to `sqrt' in GCC

When we use "math.h" functions in our C program we often get error like "undefined reference to `sqrt' " while compiling the program using GCC.

We can get rid of the error by explicitly linking the math library while building the executable.

To do the same in Unix/Linux just add 'lm' at the the end of the command.
(Note: The '-lm' should be at the end)

For ex : gcc test.c -o test -lm

No comments:

Post a Comment

Base and Bounds, Segmentation

Base & bounds relocation: Two hardware registers: base address for process, bounds register that indicates the last valid address t...