(This is a first try, to demonstrate principles- we'll look at the "proper" method later)
$ gcc -fPIC -g -c -Wall mod1.c mod2.c mod3.c
-fPIC (Position Independent Code) causes compiler to generate code that can be loaded anywhere in virtual memory at run-time.
$ gcc -shared -o libfoo.so mod1.o mod2.o mod3.o
Usual naming convention: libname.so[.version]
$ gcc -g -Wall -o prog prog.c libfoo.so
or:
$ gcc -g -Wall -o prog prog.c -L. -lfoo
This step embeds name of shared library inside executable file.
(C) 2006, Michael Kerrisk