Fix Jira issue #ROOT-5858 (Missing library search path)
Solve the problem by asking the system its library search path (thanks Axel for the tip)
This commit is contained in:
parent
098870d14d
commit
d7fc31cf92
@ -13,6 +13,9 @@
|
|||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
@ -94,11 +97,44 @@ namespace cling {
|
|||||||
if (llvm::sys::fs::is_directory(llvm::StringRef(at)))
|
if (llvm::sys::fs::is_directory(llvm::StringRef(at)))
|
||||||
Paths.push_back(at);
|
Paths.push_back(at);
|
||||||
}
|
}
|
||||||
|
static bool initialized = false;
|
||||||
Paths.push_back("/usr/local/lib/");
|
static std::vector<std::string> SysPaths;
|
||||||
Paths.push_back("/usr/X11R6/lib/");
|
if (!initialized) {
|
||||||
Paths.push_back("/usr/lib/");
|
// trick to get the system search path
|
||||||
Paths.push_back("/lib/");
|
std::string cmd("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls 2>&1");
|
||||||
|
FILE *pf = popen(cmd.c_str (), "r");
|
||||||
|
std::string result = "";
|
||||||
|
std::string sys_path = "";
|
||||||
|
char buffer[128];
|
||||||
|
while (!feof(pf)) {
|
||||||
|
if (fgets(buffer, 128, pf) != NULL)
|
||||||
|
result += buffer;
|
||||||
|
}
|
||||||
|
pclose(pf);
|
||||||
|
std::size_t from = result.find("search path=", result.find("(LD_LIBRARY_PATH)"));
|
||||||
|
std::size_t to = result.find("(system search path)");
|
||||||
|
if (from != std::string::npos && to != std::string::npos) {
|
||||||
|
from += 12;
|
||||||
|
sys_path = result.substr(from, to-from);
|
||||||
|
sys_path.erase(std::remove_if(sys_path.begin(), sys_path.end(), isspace), sys_path.end());
|
||||||
|
sys_path += ':';
|
||||||
|
}
|
||||||
|
static const char PathSeparator = ':';
|
||||||
|
const char* at = sys_path.c_str();
|
||||||
|
const char* delim = strchr(at, PathSeparator);
|
||||||
|
while (delim != 0) {
|
||||||
|
std::string tmp(at, size_t(delim-at));
|
||||||
|
if (llvm::sys::fs::is_directory(tmp.c_str()))
|
||||||
|
SysPaths.push_back(tmp);
|
||||||
|
at = delim + 1;
|
||||||
|
delim = strchr(at, PathSeparator);
|
||||||
|
}
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
std::vector<std::string>::const_iterator it = SysPaths.begin();
|
||||||
|
while ((++it) != SysPaths.end()) {
|
||||||
|
Paths.push_back((*it).c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#elif defined(LLVM_ON_WIN32)
|
#elif defined(LLVM_ON_WIN32)
|
||||||
static void GetSystemLibraryPaths(llvm::SmallVectorImpl<std::string>& Paths) {
|
static void GetSystemLibraryPaths(llvm::SmallVectorImpl<std::string>& Paths) {
|
||||||
|
Loading…
Reference in New Issue
Block a user