Ticket #6799: test-dlopen.c

File test-dlopen.c, 482 bytes (added by Christophe Dumez <christophe.dumez@…>, 11 years ago)

test app which calls dlopen/dlclose

Line 
1// Build with:
2// gcc -O0 -g -ldl -lpthread test-dlopen.c -o test-dlopen
3
4#include <dlfcn.h>
5#include <stdio.h>
6
7int main (int argc, char *argv[])
8{
9 char* libs[2] = {
10 "./libchild.so",
11 "/usr/lib/libboost_date_time.so"
12 };
13 int i;
14
15 for (i=0; i<2; ++i) {
16 printf("trying to load %s...\n", libs[i]);
17 void *mh = dlopen(libs[i], RTLD_NOW);
18 if (!mh) {
19 fprintf(stderr, "Failed to load: %s\n", dlerror());
20 continue;
21 }
22
23 dlclose(mh);
24 }
25
26 return 0;
27}