You can specify the search path(s) used by ld at runtime to find shared objects by building your program with the -rpath option:
$ gcc -Xlinker -rpath -Xlinker /path/to/my/libraries filename.c
This is the equivalent of:
$ ld -rpath /path/to/my/libraries filename.o
ccommandscompilationgcclanguagesldlinkingprogramming