/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 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. */ #if defined(WIN32) && !defined(__CYGWIN__) #include #include #include #elif defined(__DARWIN_OSX__) #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 using namespace osg; using namespace osgDB; DynamicLibrary::DynamicLibrary(const std::string& name,HANDLE handle) { _name = name; _handle = handle; } DynamicLibrary::~DynamicLibrary() { if (_handle) { #if defined(WIN32) && !defined(__CYGWIN__) FreeLibrary((HMODULE)_handle); #elif defined(__DARWIN_OSX__) NSUnLinkModule(_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) { std::string fullLibraryName = osgDB::findLibraryFile(libraryName); if (fullLibraryName.empty()) return NULL; #if defined(WIN32) && !defined(__CYGWIN__) HANDLE handle = LoadLibrary( fullLibraryName.c_str() ); if (handle) return new DynamicLibrary(libraryName,handle); notify(WARN) << "DynamicLibrary::failed loading "<(&_handle), procName.c_str(), TYPE_PROCEDURE, result) == 0) { return result; } else { notify(WARN) << "DynamicLibrary::failed looking up " << procName << std::endl; notify(WARN) << "DynamicLibrary::error " << strerror(errno) << std::endl; return NULL; } #else // other unix void* sym = dlsym( _handle, procName.c_str() ); if (!sym) { notify(WARN) << "DynamicLibrary::failed looking up " << procName << std::endl; notify(WARN) << "DynamicLibrary::error " << dlerror() << std::endl; } return sym; #endif return NULL; }