Skip to content

Instantly share code, notes, and snippets.

@0xef967c36 0xef967c36/solibs-test

Last active Apr 11, 2020
Embed
What would you like to do?
solibs with DT_RUNPATH example
mkdir -p b a
echo 'void b(){ puts("b"); }' > b.c
cc -include stdio.h -shared b.c -o b/libb.so
echo 'int main(){ extern void b(); b(); }' > m.c
cc m.c -o m -Wl,-rpath=./b -L ./b -lb
./m
# => b
# now we create a _different_ b/libb.so linking to a a/liba.so
# the ./m doesn't know about
echo 'void a(){ puts("a"); }' > a.c
cc -include stdio.h -shared a.c -o a/liba.so
echo 'void b(){ extern void a(); a(); }' > b.c
cc -shared -Wl,-rpath=./a b.c -L ./a -la -o b/libb.so
./m
# => a
rm a/liba.so
./m
# => ./m: error while loading shared libraries: liba.so: cannot open shared object file: No such file or directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.