OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <dlfcn.h> |
| 6 #include <stdio.h> |
| 7 |
| 8 extern "C" bool Zoo() { |
| 9 printf("%s: Entering\n", __FUNCTION__); |
| 10 void* bar_lib = dlopen("libbar.so", RTLD_NOW); |
| 11 if (!bar_lib) { |
| 12 fprintf(stderr, "Could not libbar.so: %s\n", dlerror()); |
| 13 return false; |
| 14 } |
| 15 printf("%s: Opened libbar.so @%p\n", __FUNCTION__, bar_lib); |
| 16 |
| 17 void (*bar_func)(); |
| 18 |
| 19 bar_func = reinterpret_cast<void (*)()>(dlsym(bar_lib, "Bar")); |
| 20 if (!bar_func) { |
| 21 fprintf(stderr, "Could not find 'Bar' symbol in libbar.so\n"); |
| 22 return false; |
| 23 } |
| 24 printf("%s: Found 'Bar' symbol at @%p\n", __FUNCTION__, bar_func); |
| 25 |
| 26 // Call it. |
| 27 printf("%s: Calling Bar()\n", __FUNCTION__); |
| 28 (*bar_func)(); |
| 29 |
| 30 printf("%s: Closing libbar.so\n", __FUNCTION__); |
| 31 dlclose(bar_lib); |
| 32 |
| 33 printf("%s: Exiting\n", __FUNCTION__); |
| 34 return true; |
| 35 } |
OLD | NEW |