#include "application.h" #include "../../utils/exceptionstream.h" #include #include #include int bar_( static base&) { printf( "bar_( base& b) called\n"); return 1; } int main( int argc, char** argv) { try { std::cerr << "Dynamic-linking multimethod application started\n\n"; if ( argc != 2) throw exception_stream() << "Params: "; const char* sharedlib_filename = argv[1]; derived d; base b; std::cerr << "calling multimethod with type base : "; bar( b); std::cerr << "calling multimethod with type derived: "; bar( d); std::cerr << "\nLoading library " << sharedlib_filename << "..."; void* lib = dlopen( sharedlib_filename, RTLD_LAZY); if ( !lib) throw exception_stream() << "dlopen failed"; std::cerr << " Have loaded library\n\n"; // these are raw symbol names for gcc 2.95.3/gcc3.2 on openbsd 3.2 //void* sym = dlsym( lib, "__Z33bar_cmm_implcall1_2_4base7derivedR4base"); //void* sym = dlsym( lib, "_bar_cmm_implcall1_2_4base7derived__FR4base"); //std::cerr << "dlsym returned " << sym << "\n"; std::cerr << "calling multimethod with type base : "; bar( b); std::cerr << "calling multimethod with type derived: "; bar( d); std::cerr << "\nUnloading library " << sharedlib_filename << "..."; dlclose( lib); std::cerr << " Have unloaded library\n\n"; std::cerr << "calling multimethod with type base : "; bar( b); std::cerr << "calling multimethod with type derived: "; bar( d); std::cerr << "\n"; return 0; } catch( std::exception& e) { std::cerr << "Exception caught in main(): " << e.what() <<" \n"; } return 1; }