why do we need the shared library during compile time

前端 未结 2 461
长发绾君心
长发绾君心 2021-02-05 07:08

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

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 07:23

    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.

提交回复
热议问题