I use Ubuntu 20.04. I write my C program using default text editor and compile the same using the following Syntax -
gcc code.c -o codeObjectName
I'm facing the problem almost/exactly similar to this: Undefined reference to pow( ) in C, despite including math.h
I have a C program where I have used the standard pow function from math.h header file. I have even Included math.h header file aswell in code. But when I compile, I'm getting this error message on my terminal -
/usr/bin/ld: /tmp/xxxxxxxx.o: in function `numerize':
code.c:(.text+0x73): undefined reference to `pow'
collect2: error: ld returned 1 exit status
In the answer to the above attached question, it was given that the linker couldn't find the definition for 'pow' function, for this to work, we have to manually link it with math library.
My question is, even though I included math.h header file, why doesn't the compiler/linker link the libm.a library automatically, just like the libraries of all the functions like prinf, scanf, malloc, etc. are automatically linked?