dynamic path init from LD_LIBRARY_PATH

From: Dave Morrison (dave@bnl.gov)
Date: Fri Sep 10 1999 - 18:54:19 MEST


Hi,

One of the recurring troubles we run into can be traced (in my opinion) to the
fact that ROOT's dynamic loading mechanism doesn't use LD_LIBRARY_PATH.  Here's
a simple patch to teach it how:

--- root.orig/src/UNIX_UnixSystem.cxx	Wed Jul 28 04:41:08 1999
+++ root/src/UNIX_UnixSystem.cxx	Fri Sep 10 12:38:26 1999
@@ -2317,13 +2317,18 @@
 const char *TUnixSystem::GetDynamicPath()
 {
    // Get shared library search path. Static utility function.
-
+   static const char *rootdynpath = 0;
    static const char *dynpath = 0;
+   static const char *tmp = 0;
 
    if (dynpath == 0) {
-      dynpath = gEnv->GetValue("Root.DynamicPath", (char*)0);
-      if (dynpath == 0)
-         dynpath = StrDup(Form(".:%s/lib", gRootDir));
+      tmp = gEnv->GetValue("Root.DynamicPath", (char*)0);
+      rootdynpath = getenv("ROOTDYNPATH");
+      if (tmp == 0) {
+	 dynpath = StrDup(Form(".:%s", rootdynpath));
+      } else {
+	 dynpath = StrDup(Form("%s:%s", tmp, rootdynpath));
+      }
    }
    return dynpath;
 }
--- root.orig/src/ROOTX_rootx.cxx	Wed Jul 28 04:48:17 1999
+++ root/src/ROOTX_rootx.cxx	Fri Sep 10 12:39:26 1999
@@ -191,6 +191,38 @@
    putenv((char *)msg);
 }
 
+static void SetDynamicPath()
+{
+   // Init dynamic loading path for the different platforms.
+
+   static char msg[512];
+
+#if defined(__linux) || defined(__alpha) || defined(__sgi) || defined(__sun) ||
\
+    defined(__FreeBSD__)
+   if (getenv("LD_LIBRARY_PATH"))
+      sprintf(msg, "ROOTDYNPATH=%s:%s/lib", 
+	      getenv("LD_LIBRARY_PATH"),
+	      getenv("ROOTSYS"));
+   else
+      sprintf(msg, "ROOTDYNPATH=%s/lib", getenv("ROOTSYS"));
+#elif defined(__hpux)  || defined(_HIUX_SOURCE)
+   if (getenv("SHLIB_PATH"))
+      sprintf(msg, "ROOTDYNPATH=%s:%s/lib", 
+	      getenv("SHLIB_PATH"),
+	      getenv("ROOTSYS"));
+   else
+      sprintf(msg, "ROOTDYNPATH=%s/lib", getenv("ROOTSYS"));
+#elif defined(_AIX)
+   if (getenv("LIBPATH"))
+      sprintf(msg, "ROOTDYNPATH=%s:%s/lib", 
+	      getenv("LIBPATH"),
+	      getenv("ROOTSYS"));
+   else
+      sprintf(msg, "ROOTDYNPATH=%s/lib", getenv("ROOTSYS"));
+#endif
+   putenv((char *)msg);
+}
+
 static void SigUsr1(int)
 {
    // When we get SIGUSR1 from child (i.e. ROOT) then pop down logo.
@@ -332,6 +364,9 @@
 
    // Make sure library path is set
    SetLibraryPath();
+
+   // Initialize the path for locating dynamically loaded libraries
+   SetDynamicPath();
 
    // Execute actual ROOT module
    execv(arg0, argvv);


Enjoy,
Dave

-- 
David Morrison  Brookhaven National Laboratory  phone: 516-344-5840
                Physics Department, Bldg 510 C    fax: 516-344-3253
		          Upton, NY 11973-5000  email: dave@bnl.gov



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:39 MET