By default, the linker will link against the shared libraries if they are available. But -Bdynamic and -Bstatic provides finer control of which library, shared or static should searched for each library specified for the linker. The library search option is toggled by each -Bdynamic or -Bstatic:
# ld ... -Bstatic -lfoo -Bdynamic -lbar ....
This command tells the linker to search the static library for libfoo, and search the shared version for libbar and any libraries after it until a -Bstatic is seen.
To pass the -Bdynamic and -Bstatic options to the linker, one needs to do
# gcc -o main main.o -Wl,-Bstatic -lfoo -Wl,-Bdynamic -lbar
Since the gcc driver calls the linker with some default libraries,
# gcc -o main main.o -Wl,-Bstatic
tells the linker to use the static versions for all default libraries like libc and etc.