1 #include <sys/param.h>
2 #include <err.h>
3 #include <dlfcn.h>
4 
5 #ifdef __ELF__
6 #define C_LABEL(x) x
7 #else
8 #define C_LABEL(x) "_" ## x
9 #endif
10 
11 int
12 main()
13 {
14 	void *handle = dlopen("libtest.so", DL_LAZY);
15 	void (*version)(void);
16 
17 	if (handle == NULL)
18 		errx(1, "could not dynamically link libtest");
19 	version = dlsym(handle, C_LABEL("version"));
20 	if (version == NULL)
21 		errx(2, "libtest did not define version()");
22 	version();
23 	dlclose(handle);
24 	return 0;
25 }
26