Q:

Linking - which library is included?

The gcc man page says, "Order does matter when you use several options of the same kind; for example, if you specify -L more than once, the directories are searched in the order specified."
However, are these -L directories searched before the system directories (e.g., those that ld normally uses)? 
I have the case that I have two libraries of the same name, one in a system location and another in my working directory, and I want to use mine, but cannot figure out how to verify my version is being used.

A:

Try "ldd /bin/your/application". E.g:
ldd `which bash`
linux-vdso.so.1 =>  (0x00007fff46eda000)
libncurses.so.5 => /lib/libncurses.so.5 (0x00007facdd618000)
libdl.so.2 => /lib/libdl.so.2 (0x00007facdd414000)
libc.so.6 => /lib/libc.so.6 (0x00007facdd090000)
/lib64/ld-linux-x86-64.so.2 (0x00007facdd863000)

In general there are 3 options how one can specify which library to use for your binary:

Setting LD_LIBRARY_PATH environment variable before starting your executable
RPATH linker option (see other my questions/answers on SO to find out more about this option)
Add your shared library to all other system libraries.

