/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ //The dlopen calls were not adding to OS X until 10.3 #ifdef __APPLE__ #include #if !defined(MAC_OS_X_VERSION_10_3) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3) #define APPLE_PRE_10_3 #endif #endif #if defined(WIN32) && !defined(__CYGWIN__) #include #include #include #elif defined(__APPLE__) && defined(APPLE_PRE_10_3) #include #else // all other unix #include #ifdef __hpux // Although HP-UX has dlopen() it is broken! We therefore need to stick // to shl_load()/shl_unload()/shl_findsym() #include #include #else #include #endif #endif #include #include #include #include #include #include using namespace osgDB; DynamicLibrary::DynamicLibrary(const std::string& name, HANDLE handle) { _name = name; _handle = handle; OSG_INFO<<"Opened DynamicLibrary "<<_name<(_handle), FALSE); #elif defined(__hpux) // fortunately, shl_t is a pointer shl_unload (static_cast(_handle)); #else // other unix dlclose(_handle); #endif } } DynamicLibrary* DynamicLibrary::loadLibrary(const std::string& libraryName) { HANDLE handle = NULL; std::string fullLibraryName = osgDB::findLibraryFile(libraryName); if (!fullLibraryName.empty()) handle = getLibraryHandle( fullLibraryName ); // try the lib we have found else handle = getLibraryHandle( libraryName ); // havn't found a lib ourselves, see if the OS can find it simply from the library name. if (handle) return new DynamicLibrary(libraryName,handle); // else no lib found so report errors. OSG_INFO << "DynamicLibrary::failed loading \""<( GetProcAddress( (HMODULE)_handle, procName.c_str() ) ); #elif defined(__APPLE__) && defined(APPLE_PRE_10_3) std::string temp("_"); NSSymbol symbol; temp += procName; // Mac OS X prepends an underscore on function names symbol = NSLookupSymbolInModule(static_cast(_handle), temp.c_str()); return NSAddressOfSymbol(symbol); #elif defined(__hpux) void* result = NULL; if (shl_findsym (reinterpret_cast(&_handle), procName.c_str(), TYPE_PROCEDURE, result) == 0) { return result; } else { OSG_WARN << "DynamicLibrary::failed looking up " << procName << std::endl; OSG_WARN << "DynamicLibrary::error " << strerror(errno) << std::endl; return NULL; } #else // other unix void* sym = dlsym( _handle, procName.c_str() ); if (!sym) { OSG_WARN << "DynamicLibrary::failed looking up " << procName << std::endl; OSG_WARN << "DynamicLibrary::error " << dlerror() << std::endl; } return sym; #endif }