When I have a single C file for example, example.c
and I need to use a method from a library, let's say math.h
, at the top of my example.c
I will have #include <math.h>
and during the preprocessor stage it will take the function declarations out of math.h
and place them into my math.c
. The file will then be compiled and at this stage I will have an object file with an empty memory address pointing to the function I could be using inside math.h
, let us says ceil
. Only during the linking stage will the reference to the function ceil
from the math.h
library be corrected placed so that it can use the function correctly.
However, suppose I am writing the function ceil
and I created my own math.c
and math.h
files, why does it need to be linked when I do not necessarily need to reference anything. Suppose inside my math.c
I create a function add
, that very simply, returns the addition of two given parameters, I don
't need to import anything, I don't reference anything, I have a very simple library with one function that adds two numbers, what exactly will happen during the linking stage when making my library?