#include <iostream>
#include <dlfcn.h>
Go to the source code of this file.
Functions | |
int | main () |
int main | ( | ) |
Definition at line 5 of file test.cxx.
00005 { 00006 using std::cout; 00007 using std::cerr; 00008 00009 cout << "C++ dlopen demo\n\n"; 00010 00011 // open the library 00012 cout << "Opening TrkBase.so...\n"; 00013 void* handle = dlopen("../rh73_gcc32/libTrkBase.so", RTLD_LAZY); 00014 00015 if (!handle) { 00016 cerr << "Cannot open library: " << dlerror() << '\n'; 00017 return 1; 00018 } 00019 00020 /* // load the symbol 00021 cout << "Loading symbol hello...\n"; 00022 typedef void (*hello_t)(); 00023 hello_t hello = (hello_t) dlsym(handle, "hello"); 00024 if (!hello) { 00025 cerr << "Cannot load symbol 'hello': " << dlerror() << 00026 '\n'; 00027 dlclose(handle); 00028 return 1; 00029 } 00030 00031 // use it to do the calculation 00032 cout << "Calling hello...\n"; 00033 hello(); 00034 */ 00035 // close the library 00036 cout << "Closing library...\n"; 00037 dlclose(handle); 00038 }