Skip to content

Instantly share code, notes, and snippets.

@farseerfc
Created May 6, 2019 16:06
Show Gist options
  • Save farseerfc/e607fac3e05f9a570f764eb489d51bd1 to your computer and use it in GitHub Desktop.
Save farseerfc/e607fac3e05f9a570f764eb489d51bd1 to your computer and use it in GitHub Desktop.
trydlopen
#include <stdio.h>
void a_f(){
printf("a_f\n");
}
#include <stdio.h>
void a_f();
void b_f(){
a_f();
printf("b_f\n");
}
#include <dlfcn.h>
int main(int argc, char* argv[]){
void (*b_p) ();
void * b_so = 0;
b_so = dlopen("libb.so.1", RTLD_LAZY);
b_p = dlsym(b_so, "b_f");
b_p();
}
all: main libb.so.1.0 liba.so.1.0
libb.so.1.0: b.c
gcc --shared -Wl,-soname,libb.so.1 -o libb.so.1.0 b.c
ln -sr libb.so.1.0 libb.so.1
liba.so.1.0: a.c
gcc --shared -Wl,-soname,liba.so.1 -o liba.so.1.0 a.c
ln -sr liba.so.1.0 liba.so.1
main: main.c liba.so.1.0
gcc -Wl,-rpath=. -ldl -o main main.c liba.so.1.0
clean:
rm main *.so.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment