summaryrefslogtreecommitdiff
path: root/testsuite/tests/dynlibs/T3807-load.c
blob: 8c6f252c5f83da105c207a1b6fc5877a61f01143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <dlfcn.h>
#include <stdio.h>

int main(void) {
    int i;
    void *dh;
    void (*test_init)(void);
    int (*test_foo)(void);
    void (*test_exit)(void);

    dh = dlopen("./T3807test.so", RTLD_NOW | RTLD_GLOBAL);
    if (!dh) {
        printf("Failed to open shared library: %s\n", dlerror());
        return 1;
    }

    test_init = dlsym(dh, "test_init");
    if (!test_init) {
        printf("Failed to find test_init: %s", dlerror());
        return 1;
    }
    test_foo = dlsym(dh, "foo");
    if (!test_foo) {
        printf("Failed to find test_foo: %s", dlerror());
        return 1;
    }
    test_exit = dlsym(dh, "test_exit");
    if (!test_exit) {
        printf("Failed to find test_exit: %s", dlerror());
        return 1;
    }

    test_init();
    i = test_foo();
    printf("i is %d\n", i);
    test_exit();

    return 0;
}