OSDN Git Service

Set LD_LIBRARY_PATH in unix run environments.
authorChristian Kamm <christian.d.kamm@nokia.com>
Wed, 27 Apr 2011 11:21:24 +0000 (13:21 +0200)
committerChristian Kamm <christian.d.kamm@nokia.com>
Thu, 28 Apr 2011 08:44:57 +0000 (10:44 +0200)
Similarly to how PATH is set up for Windows. The background is that
without it plugin loading can pull in incompatible Qt libraries if the
binary is compiled with RUNPATH instead of RPATH.

Reviewed-by: Daniel Teske
src/libs/utils/environment.cpp
src/libs/utils/environment.h
src/plugins/qt4projectmanager/qt-desktop/qt4runconfiguration.cpp
src/plugins/qt4projectmanager/qtversionmanager.cpp

index 20f822f..6ea9ce9 100644 (file)
@@ -174,6 +174,27 @@ void Environment::prependOrSetPath(const QString &value)
     prependOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value), QString(sep));
 }
 
+void Environment::prependOrSetLibrarySearchPath(const QString &value)
+{
+#ifdef Q_OS_WIN
+    const QChar sep = QLatin1Char(';');
+#else
+    const QChar sep = QLatin1Char(':');
+#endif
+
+#ifdef Q_OS_WIN
+    const QLatin1String path("PATH");
+#elif defined(Q_OS_MAC)
+    const QLatin1String path("DYLD_LIBRARY_PATH");
+#elif defined(Q_OS_UNIX)
+    const QLatin1String path("LD_LIBRARY_PATH");
+#else
+    return;
+#endif
+
+    prependOrSet(path, QDir::toNativeSeparators(value), QString(sep));
+}
+
 Environment Environment::systemEnvironment()
 {
     return Environment(QProcess::systemEnvironment());
index a2a0bf8..4c9a079 100644 (file)
@@ -85,6 +85,8 @@ public:
     void appendOrSetPath(const QString &value);
     void prependOrSetPath(const QString &value);
 
+    void prependOrSetLibrarySearchPath(const QString &value);
+
     void clear();
     int size() const;
 
index ef4e8e0..f524212 100644 (file)
@@ -600,15 +600,13 @@ Utils::Environment Qt4RunConfiguration::baseEnvironment() const
         env.set("DYLD_IMAGE_SUFFIX", "_debug");
     }
 
-#ifdef Q_OS_WIN
-    // On windows the user could be linking to a library found via a -L/some/dir switch
+    // The user could be linking to a library found via a -L/some/dir switch
     // to find those libraries while actually running we explicitly prepend those
-    // dirs to the path
+    // dirs to the library search path
     const Qt4ProFileNode *node = qt4Target()->qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath);
     if (node)
         foreach(const QString &dir, node->variableValue(LibDirectoriesVar))
-            env.prependOrSetPath(dir);
-#endif
+            env.prependOrSetLibrarySearchPath(dir);
     return env;
 }
 
index 35614af..4bd0d55 100644 (file)
@@ -1722,6 +1722,7 @@ void QtVersion::addToEnvironment(Utils::Environment &env) const
     // Generic:
     env.set("QTDIR", QDir::toNativeSeparators(versionInfo().value("QT_INSTALL_DATA")));
     env.prependOrSetPath(versionInfo().value("QT_INSTALL_BINS"));
+    env.prependOrSetLibrarySearchPath(versionInfo().value("QT_INSTALL_LIBS"));
 
     // Symbian specific:
     if (supportsTargetId(Constants::S60_DEVICE_TARGET_ID)