From b7eeeea8d13898c054f8bea49dcb5d2ca7b6a1e0 Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Thu, 6 Nov 2003 04:08:53 +0000 Subject: [PATCH] Fixed loading of dynamic libraries with dlopen if the library is in the current directory --- src/osgDB/DynamicLibrary.cpp | 13 +++++++++++-- src/osgDB/FileUtils.cpp | 21 ++++++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/osgDB/DynamicLibrary.cpp b/src/osgDB/DynamicLibrary.cpp index 96853cb25..8a4c12c8f 100644 --- a/src/osgDB/DynamicLibrary.cpp +++ b/src/osgDB/DynamicLibrary.cpp @@ -32,6 +32,7 @@ #include #include +#include using namespace osg; using namespace osgDB; @@ -125,9 +126,17 @@ DynamicLibrary::getLibraryHandle( const std::string& libraryName) BIND_DEFERRED|BIND_FIRST|BIND_VERBOSE, 0); return handle; #else // other unix - handle = dlopen( libraryName.c_str(), RTLD_LAZY | RTLD_GLOBAL); + + // dlopen will not work with files in the current directory unless + // they are prefaced with './' (DB - Nov 5, 2003). + std::string localLibraryName; + if( libraryName == osgDB::getSimpleFileName( libraryName ) ) + localLibraryName = "./" + libraryName; + else + localLibraryName = libraryName; + handle = dlopen( localLibraryName.c_str(), RTLD_LAZY | RTLD_GLOBAL); if( handle == NULL ) - printf( "dlopen: %s\n", dlerror() ); + notify(WARN) << "DynamicLibrary::getLibraryHandle( "<< libraryName << ") - dlopen(): " << dlerror() << std::endl; #endif return handle; } diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 98e4db45e..3a80bfc9f 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -45,9 +45,14 @@ bool osgDB::fileExists(const std::string& filename) std::string osgDB::findFileInPath(const std::string& filename, const FilePathList& filepath) { - if (filename.empty()) return filename; + if (filename.empty()) + return filename; - if(fileExists(filename)) return filename; + if(fileExists(filename)) + { + osg::notify(osg::DEBUG_INFO) << "FindFileInPath(" << filename << "): returning " << filename << std::endl; + return filename; + } for(FilePathList::const_iterator itr=filepath.begin(); itr!=filepath.end(); @@ -55,7 +60,11 @@ std::string osgDB::findFileInPath(const std::string& filename, const FilePathLis { std::string path = *itr + '/'+ filename; osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : trying " << path << " ...\n"; - if(fileExists(path)) return path; + if(fileExists(path)) + { + osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : USING " << path << "\n"; + return path; + } } return std::string(); @@ -84,12 +93,14 @@ std::string osgDB::findDataFile(const std::string& filename) std::string osgDB::findLibraryFile(const std::string& filename) { - if (filename.empty()) return filename; + if (filename.empty()) + return filename; const FilePathList& filepath = Registry::instance()->getLibraryFilePathList(); std::string fileFound = findFileInPath(filename, filepath); - if (!fileFound.empty()) return fileFound; + if (!fileFound.empty()) + return fileFound; // if a directory is included in the filename, get just the (simple) filename itself and try that std::string simpleFileName = getSimpleFileName(filename);