I can build a executable with gcc with static link:
gcc -static xxx.c -o xxx
So I can run xxx without any external dependent lib
There's some neat hackery you can do with Rpath so that a ELF executable or .so will look for its dependent .so files first in the same directory as itself:
make a short script echo-rpath consisting of
echo '-Wl,--rpath=$ORIGIN'
add that to your build command line as gcc -o file -lwhatever `echo-rpath ` objects
(The echo mechanism prevents Make or the shell from eating the $ sign and ensures it gets passed into ld.)