You can use the same command string to link a static or shared library to your main program. For example:
xlc -o myprogram main.c -Ldirectory [-Rdirectory] -lfoo
where directory is the path to the directory containing the library.
By using the -l option, you instruct the linker to search in the directory specified via the -L option (and, for a shared library, the -R option) for libfoo.so; if it is not found, the linker searches for libfoo.a. For additional linkage options, including options that modify the default behavior, see the operating system ld documentation.