Fixed loading of dynamic libraries with dlopen if the library is

in the current directory
This commit is contained in:
Don BURNS
2003-11-06 04:08:53 +00:00
parent e043f6c89d
commit b7eeeea8d1
2 changed files with 27 additions and 7 deletions

View File

@@ -32,6 +32,7 @@
#include <osgDB/DynamicLibrary>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
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;
}

View File

@@ -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);