First, there is a need to generate a position-independent code. To do this, GCC needs to add compilation options -fpic gcc -fpic -o -c libbar.c
At this time, it is suitable for constructing shared libraries, plus -shared compile option gcc -shared -o libbar.so libbar.o can add a number of relocation files to the shared library. To connect the Baz.o and shared libraries, you can do this: # gcc -o -c baz.c # gcc -o baz baz.o -l. -Lbar