GaudiTestMain.cpp
Go to the documentation of this file.00001 #include <string>
00002 #include <iostream>
00003
00004 #ifdef WIN32
00005 extern "C" __declspec(dllimport) void* __stdcall LoadLibraryA(const char*);
00006 extern "C" __declspec(dllimport) void* __stdcall GetProcAddress(void*, const char*);
00007 #define LOAD_LIB(x) ::LoadLibraryA( x )
00008 #define GETPROC(h,x) ::GetProcAddress ( h, #x )
00009
00010 #endif
00011
00012 #ifndef WIN32
00013
00014 #include <dlfcn.h>
00015 #include <unistd.h>
00016 void* LOAD_LIB(const char* x) {
00017 std::string l = "lib"; l+=x; l+=".so";
00018 return ::dlopen( l.c_str() , RTLD_NOW|RTLD_GLOBAL);
00019
00020 }
00021 #define GETPROC(h,x) ::dlsym ( h, #x )
00022 #endif
00023 #include <vector>
00024 #include <algorithm>
00025
00026 int main (int argc, char** argv) {
00027 if ( argc < 2 ) {
00028 std::cout << "Usage: main.exe <example library> arg [arg [arg]]" << std::endl;
00029 }
00030 else {
00031 typedef long (*func)(int, char**);
00032
00033 void* handle = LOAD_LIB( argv[1] );
00034 if ( 0 != handle ) {
00035 func fun = (func)GETPROC(handle, ExampleMain );
00036 if ( fun ) {
00037 return (*fun)(argc, argv);
00038 }
00039 std::cout << "Failed to access test procedure ExampleMain" << std::endl;
00040 return 0;
00041 }
00042 std::cout << "Failed to load test library:" << argv[1] << std::endl;
00043 #ifdef WIN32
00044 #else
00045 std::cout << "Error:" << ::dlerror() << std::endl;
00046 #endif
00047 }
00048 return 0;
00049 }