Browse Source

Merge pull request #4754 from richardkchapman/no-so-append

HPCC-9890 Dynamic loading assumes .so extension (so can fail on OSX)

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 12 years ago
parent
commit
ed4b24497d
1 changed files with 9 additions and 5 deletions
  1. 9 5
      system/jlib/jutil.cpp

+ 9 - 5
system/jlib/jutil.cpp

@@ -332,12 +332,16 @@ HINSTANCE LoadSharedObject(const char *name, bool isGlobal, bool raiseOnError)
     if(h == NULL)
     if(h == NULL)
     {
     {
         // Try again, with .so extension if necessary
         // Try again, with .so extension if necessary
-        if (strncmp(".so", name+(strlen(name)-3), 3) != 0)
+        StringBuffer path, tail, ext;
+        splitFilename(name, &path, &path, &tail, &ext, false);
+        if (!streq(ext.str(), SharedObjectExtension))
         {
         {
-            // Assume if there's no .so, there's also no lib at the beginning
-            StringBuffer nameBuf;
-            nameBuf.append("lib").append(name).append(".so");
-            h = dlopen((char *)nameBuf.str(), isGlobal ? RTLD_NOW|RTLD_GLOBAL : RTLD_NOW);
+            // Assume if there's no .so, there may also be no lib at the beginning
+            if (strncmp(tail.str(), SharedObjectPrefix, strlen(SharedObjectPrefix) != 0))
+                path.append(SharedObjectPrefix);
+            path.append(tail).append(ext).append(SharedObjectExtension);
+            name = path.str();
+            h = dlopen((char *)name, isGlobal ? RTLD_NOW|RTLD_GLOBAL : RTLD_NOW);
         }
         }
         if (h == NULL)
         if (h == NULL)
         {
         {