feat: add load.c
This commit is contained in:
24
live-reload-rust/load.c
Normal file
24
live-reload-rust/load.c
Normal 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;
|
||||||
|
}
|
||||||
1
live-reload-rust/load.c-compile.sh
Executable file
1
live-reload-rust/load.c-compile.sh
Executable file
@@ -0,0 +1 @@
|
|||||||
|
gcc -Wall load.c -o load
|
||||||
Reference in New Issue
Block a user