Last active
March 8, 2023 06:56
-
-
Save liviaerxin/38713f488ee3dc262581ff7c433cc6d9 to your computer and use it in GitHub Desktop.
dlopen_test.c #dlopen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* clang -Wall -Wextra -o dlopen_test.out dlopen_test.c -ldl | |
* Usage: | |
* ./dlopen_test.out ./libOpenCvSharpExtern.dylib | |
* DYLD_PRINT_LIBRARIES=1 ./dlopen_test.out ./libOpenCvSharpExtern.dylib | |
* | |
* linux: | |
* LD_DEBUG=libs ./binary_name | |
*/ | |
#include <assert.h> | |
#include <dlfcn.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
void *handle; | |
char *error; | |
printf("dlopen sample"); | |
if (argc != 2) { | |
fprintf(stderr, "Usage: %s {dylib_path}\n", argv[0]); | |
return EXIT_FAILURE; | |
} | |
handle = dlopen(argv[1], RTLD_LAZY); | |
if (!handle) { | |
fprintf(stderr, "%s\n", dlerror()); | |
exit(EXIT_FAILURE); | |
} | |
dlclose(handle); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment