1 #include <dlfcn.h>
2 #include <stdexcept>
3 #include <stdio.h>
4 
5 int twelve(int i) {
6   return 12 + i; // break 12
7 }
8 
9 int thirteen(int i) {
10   return 13 + i; // break 13
11 }
12 
13 namespace a {
14   int fourteen(int i) {
15     return 14 + i; // break 14
16   }
17 }
18 int main(int argc, char const *argv[]) {
19 #if defined(__APPLE__)
20   const char *libother_name = "libother.dylib";
21 #else
22   const char *libother_name = "libother.so";
23 #endif
24 
25   void *handle = dlopen(libother_name, RTLD_NOW);
26   if (handle == nullptr) {
27     fprintf(stderr, "%s\n", dlerror());
28     exit(1);
29   }
30 
31   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
32   if (foo == nullptr) {
33     fprintf(stderr, "%s\n", dlerror());
34     exit(2);
35   }
36   foo(12);
37 
38   for (int i=0; i<10; ++i) {
39     int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
40   }
41   try {
42     throw std::invalid_argument( "throwing exception for testing" );
43   } catch (...) {
44     puts("caught exception...");
45   }
46   return 0;
47 }
48