Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <dlfcn.h>
- static const char* LIB_NAME = "?.so";
- int main(int argc, char** argv) {
- void* handle;
- double (*cosine)(double);
- char* error;
- handle = dlopen(LIB_NAME, RTLD_LAZY);
- if (!handle) {
- fprintf(stderr, "%s\n", dlerror());
- return EXIT_FAILURE;
- }
- dlerror();
- cosine = (double(*)(double)) dlsym(handle, "cos");
- *(void**)(&cosine) = dlsym(handle, "cos");
- error = dlerror();
- if (error) {
- fprintf(stderr, "%s\n", error);
- return EXIT_FAILURE;
- }
- printf("%f\n", (*cosine)(2.0));
- dlclose(handle);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement