feat: add load.c

This commit is contained in:
2020-09-30 23:55:04 +08:00
parent 8f8bc6eca9
commit 9f605830d2
2 changed files with 25 additions and 0 deletions

24
live-reload-rust/load.c Normal file
View File

@@ -0,0 +1,24 @@
#include <dlfcn.h>
#include <stdio.h>
// C function pointer syntax is... something.
// Let's typedef our way out of this one.
typedef void (*greet_t)(const char *name);
int main(void) {
// what do we want? symbols!
// when do we want them? at an implementation-defined time!
void *lib = dlopen("./main-greet", RTLD_LAZY);
if (!lib) {
fprintf(stderr, "failed to load library\n");
return 1;
}
greet_t greet = (greet_t) dlsym(lib, "greet");
if (!greet) {
fprintf(stderr, "could not look up symbol 'greet'\n");
return 1;
}
greet("venus");
dlclose(lib);
return 0;
}

View File

@@ -0,0 +1 @@
gcc -Wall load.c -o load