feat: add greet-rs

This commit is contained in:
2020-10-01 00:03:03 +08:00
parent 9f605830d2
commit ce1b7dd4fb
8 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#include <dlfcn.h>
#include <stdio.h>
typedef void (*greet_t)(const char *name);
int main(void) {
// this was `./libmain.so`
void *lib = dlopen("./libgreet.so", RTLD_LAZY);
if (!lib) {
fprintf(stderr, "failed to load library\n");
return 1;
}
greet_t greet = (greet_t) dlsym(lib, "greet");
if (!lib) {
fprintf(stderr, "could not look up symbol 'greet'\n");
return 1;
}
greet("venus");
dlclose(lib);
return 0;
}