Skip to content

Instantly share code, notes, and snippets.

@liviaerxin
Last active March 8, 2023 06:56
Show Gist options
  • Save liviaerxin/38713f488ee3dc262581ff7c433cc6d9 to your computer and use it in GitHub Desktop.
Save liviaerxin/38713f488ee3dc262581ff7c433cc6d9 to your computer and use it in GitHub Desktop.
dlopen_test.c #dlopen
/*!
* 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