1 //===-- main.c --------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include <stdio.h> 10 #include <dlfcn.h> 11 #include <limits.h> 12 #include <string.h> 13 #include <unistd.h> 14 #include <libgen.h> 15 #include <stdlib.h> 16 17 int 18 main (int argc, char const *argv[]) 19 { 20 const char *a_name = "@executable_path/liba.dylib"; 21 const char *c_name = "@executable_path/libc.dylib"; 22 void *a_dylib_handle = NULL; 23 void *c_dylib_handle = NULL; 24 int (*a_function) (void); 25 26 a_dylib_handle = dlopen (a_name, RTLD_NOW); // Set break point at this line for test_lldb_process_load_and_unload_commands(). 27 if (a_dylib_handle == NULL) 28 { 29 fprintf (stderr, "%s\n", dlerror()); 30 exit (1); 31 } 32 33 a_function = (int (*) ()) dlsym (a_dylib_handle, "a_function"); 34 if (a_function == NULL) 35 { 36 fprintf (stderr, "%s\n", dlerror()); 37 exit (2); 38 } 39 printf ("First time around, got: %d\n", a_function ()); 40 dlclose (a_dylib_handle); 41 42 c_dylib_handle = dlopen (c_name, RTLD_NOW); 43 if (c_dylib_handle == NULL) 44 { 45 fprintf (stderr, "%s\n", dlerror()); 46 exit (3); 47 } 48 a_function = (int (*) ()) dlsym (c_dylib_handle, "c_function"); 49 if (a_function == NULL) 50 { 51 fprintf (stderr, "%s\n", dlerror()); 52 exit (4); 53 } 54 55 a_dylib_handle = dlopen (a_name, RTLD_NOW); 56 if (a_dylib_handle == NULL) 57 { 58 fprintf (stderr, "%s\n", dlerror()); 59 exit (5); 60 } 61 62 a_function = (int (*) ()) dlsym (a_dylib_handle, "a_function"); 63 if (a_function == NULL) 64 { 65 fprintf (stderr, "%s\n", dlerror()); 66 exit (6); 67 } 68 printf ("Second time around, got: %d\n", a_function ()); 69 dlclose (a_dylib_handle); 70 71 int d_function(void); 72 printf ("d_function returns: %d\n", d_function()); 73 74 return 0; 75 } 76