Set LD_LIBRARY_PATH in unix run environments.

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
This commit is contained in:
Christian Kamm
2011-04-27 13:21:24 +02:00
parent 0c8b4e38fa
commit d7d23226ba
4 changed files with 27 additions and 5 deletions

View File

@@ -174,6 +174,27 @@ void Environment::prependOrSetPath(const QString &value)
prependOrSet(QLatin1String("PATH"), QDir::toNativeSeparators(value), QString(sep)); 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() Environment Environment::systemEnvironment()
{ {
return Environment(QProcess::systemEnvironment()); return Environment(QProcess::systemEnvironment());

View File

@@ -85,6 +85,8 @@ public:
void appendOrSetPath(const QString &value); void appendOrSetPath(const QString &value);
void prependOrSetPath(const QString &value); void prependOrSetPath(const QString &value);
void prependOrSetLibrarySearchPath(const QString &value);
void clear(); void clear();
int size() const; int size() const;

View File

@@ -600,15 +600,13 @@ Utils::Environment Qt4RunConfiguration::baseEnvironment() const
env.set("DYLD_IMAGE_SUFFIX", "_debug"); env.set("DYLD_IMAGE_SUFFIX", "_debug");
} }
#ifdef Q_OS_WIN // The user could be linking to a library found via a -L/some/dir switch
// On windows 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 // 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); const Qt4ProFileNode *node = qt4Target()->qt4Project()->rootProjectNode()->findProFileFor(m_proFilePath);
if (node) if (node)
foreach(const QString &dir, node->variableValue(LibDirectoriesVar)) foreach(const QString &dir, node->variableValue(LibDirectoriesVar))
env.prependOrSetPath(dir); env.prependOrSetLibrarySearchPath(dir);
#endif
return env; return env;
} }

View File

@@ -1722,6 +1722,7 @@ void QtVersion::addToEnvironment(Utils::Environment &env) const
// Generic: // Generic:
env.set("QTDIR", QDir::toNativeSeparators(versionInfo().value("QT_INSTALL_DATA"))); env.set("QTDIR", QDir::toNativeSeparators(versionInfo().value("QT_INSTALL_DATA")));
env.prependOrSetPath(versionInfo().value("QT_INSTALL_BINS")); env.prependOrSetPath(versionInfo().value("QT_INSTALL_BINS"));
env.prependOrSetLibrarySearchPath(versionInfo().value("QT_INSTALL_LIBS"));
// Symbian specific: // Symbian specific:
if (supportsTargetId(Constants::S60_DEVICE_TARGET_ID) if (supportsTargetId(Constants::S60_DEVICE_TARGET_ID)