summaryrefslogtreecommitdiff
path: root/test/dlopen/testscope.c
blob: 90e079885be4520295b3b00f4027fc48bc53f62e (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
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

#define LIBNAME "libA.so"
int main(int argc, char **argv)
{
	void *libA;
	void (*libAfn)(void);
	char *error;

	libA = dlopen(LIBNAME, RTLD_LAZY);
	if (!libA) {
		fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
		exit(1);
	}

	libAfn = dlsym(libA, "libA_func");
	if ((error = dlerror()) != NULL)  {
		fprintf(stderr, "Could not locate symbol 'libA_func': %s\n", error);
		exit(1);
	}

	libAfn();

	dlclose(libA);

	return EXIT_SUCCESS;
}