diff --git a/core/base/src/TSystem.cxx b/core/base/src/TSystem.cxx index ba5d50f0dacf9..dffb266d9461d 100644 --- a/core/base/src/TSystem.cxx +++ b/core/base/src/TSystem.cxx @@ -3418,16 +3418,18 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt, if (!f(I->c_str())) break; }; - auto LoadLibrary = [useCxxModules, produceRootmap, ForeachSharedLibDep](const TString &lib) { - // We have no rootmap files or modules to construct `-l` flags enabling - // explicit linking. We have to resolve the dependencies by ourselves - // taking the job of the dyld. + auto LoadLibrary = [linkDepLibraries, useCxxModules, produceRootmap, ForeachSharedLibDep](const TString &lib) { + // If the library was explicitly linked against its dependencies, they + // are recorded in the library itself and the dynamic linker loads them. + // Otherwise, we have no rootmap files or modules to construct `-l` flags + // enabling explicit linking. We have to resolve the dependencies by + // ourselves taking the job of the dyld. // FIXME: This is a rare case where we have rootcling running with // modules disabled. Remove this code once we fully switch to modules, // or implement a special flag in rootcling which selective enables // modules for dependent libraries and does not produce a module for // the ACLiC library. - if (useCxxModules && !produceRootmap) { + if (!linkDepLibraries && useCxxModules && !produceRootmap) { std::function LoadLibF = [](const char *dep) { return gInterpreter->Load(dep, /*skipReload*/ true) >= 0; };