Skip to content

Commit b091755

Browse files
committed
[core] Follow symlinks in TROOT::GetSharedLibDir()
The idea is to find the actual ROOT install directory, so we have to follow symlinks. The `info->dlpi_name` doesn't do that, so we need to do that ourselves with `fs::canonical()`. Closes root-project#21031.
1 parent 4cfaed9 commit b091755

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

core/base/src/TROOT.cxx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3159,7 +3159,24 @@ const TString &TROOT::GetSharedLibDir()
31593159

31603160
fs::path p = info->dlpi_name;
31613161
if (p.filename() == _R_QUOTEVAL_(LIB_CORE_NAME)) {
3162-
libdir = p.parent_path().c_str();
3162+
std::error_code ec;
3163+
3164+
// Resolve symlinks: critical for environments like CMSSW, where the
3165+
// ROOT libraries are loaded via symlinks that point to the actual
3166+
// install directory
3167+
fs::path resolved = fs::canonical(p, ec);
3168+
if (ec) {
3169+
::Error("TROOT",
3170+
"Failed to canonicalize detected ROOT shared library path:\n"
3171+
"%s\n"
3172+
"This is an unexpected internal error and ROOT might not work.\n"
3173+
"Please report this issue on GitHub: https://github.com/root-project/root/issues",
3174+
p.string().c_str());
3175+
// Fall back to the loader path if canonicalization fails. The path
3176+
// will likely be wrong, but at least not garbage
3177+
resolved = p;
3178+
}
3179+
libdir = resolved.parent_path().c_str();
31633180
return 1; // stop iteration
31643181
}
31653182
return 0; // continue

0 commit comments

Comments
 (0)