KLibLoader broken on OSX

Benjamin Reed rangerrick at gmail.com
Wed Oct 4 13:39:13 BST 2006


The changes to KLibLoader appear to have broken module-loading on OSX.
 This is the relevant bit of code:

---(snip!)---
static inline QByteArray makeLibName( const char* name )
{
    QByteArray libname(name);
    int pos = libname.lastIndexOf('/');
    if (pos < 0)
      pos = 0;
    if (libname.indexOf('.', pos) < 0) {
        const char* const extList[] = { ".dylib", ".bundle", ".so",
".dll", ".sl" };
        for (int i = 0; i < sizeof(extList) / sizeof(*extList); ++i) {
           if (QLibrary::isLibrary(libname + extList[i]))
               return libname + extList[i];
        }
    }
    return libname;
}

//static
QString KLibLoader::findLibrary( const char * name, const KInstance * instance )
{
    QByteArray libname = makeLibName( name );

    // only look up the file if it is not an absolute filename
    // (mhk, 20000228)
    QString libfile;
    if (!QDir::isRelativePath(libname)) {
      libfile = QFile::decodeName( libname );
    }
    else
    {
      libfile = instance->dirs()->findResource( "module", libname );
      if ( libfile.isEmpty() )
      {
        libfile = instance->dirs()->findResource( "lib", libname );
#ifndef NDEBUG
        if ( !libfile.isEmpty() && libname.startsWith( "lib" ) ) //
don't warn for kdeinit modules
          kDebug(150) << "library " << libname << " not found under
'module' but under 'lib'" << endl;
#endif
      }
    }
    return libfile;
}
---(snip!)---

The problem is that makeLibName will always return the first of the
list of library extensions that QLibrary accepts as a valid filename,
not the first file that actual exists.  So the only thing that
KLibLoader looks for is ".dylib" on Mac OS X, even though CMake makes
loadable modules as .so files (.dylib is only for shared libraries).

It seems like we really need to iterate over each of those extensions,
and see if the library exists and/or try to load it.  Does that seem
right?  I guess it ends up being much more expensive, but as long as
we put ".so" first, it won't try .dylib or .bundle except as a last
resort...




More information about the kde-core-devel mailing list