Why we need the presence of the shared library during the compile time of my executable? My reasoning is that since shared library is not included into my executable and is load
gcc -o main main.c -L. -lfoo
This command does (at least) two steps: compile main.c
into an object file and link all resources into an executable main
. The error you see is from the last step, the linker.
The linker is responsible for generating the final executable machine code. It requires the shared object library because it needs to generate the machine code which loads it and executes any functions used in it.