From 19127366288dd2338cdb1cd457550f4d96a8a64c Mon Sep 17 00:00:00 2001 From: Kevin Ushey Date: Thu, 23 Jul 2026 15:03:06 -0700 Subject: [PATCH] load tbb stub library on windows again RcppParallel 6.0.0 (via #241) stopped loading any TBB library in .onLoad on Windows, on the grounds that TBB is statically linked there. However, we still ship a stub tbb.dll (see src/install.libs.R) for packages that link with '-ltbb', e.g. via StanHeaders' LdFlags(). Those packages record a load-time dependency on 'tbb.dll' in their DLL's import table, and the Windows loader can only resolve it against an already-loaded module -- RcppParallel's lib/x64 directory is not on the DLL search path. As a result, with 6.0.0 on Windows, Stan-based packages fail to load with: LoadLibrary failure: The specified module could not be found. as seen with e.g. WSPsignal on r-universe: https://github.com/r-universe/cran/actions/runs/30028540221/job/89334243681 Restore the preload, resolving the stub directly (tbbLibraryPath() now reports static library names on Windows, so it cannot be used here). --- NEWS.md | 7 +++++++ R/zzz.R | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 3b535328..62cde0dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,12 @@ # RcppParallel (development version) +* On Windows, RcppParallel once again loads its compatibility stub library + (`tbb.dll`) when the package is loaded. Packages linking with `-ltbb` + (e.g. via StanHeaders) record a load-time dependency on `tbb.dll`, which + can only be resolved if RcppParallel has already loaded it; with + RcppParallel 6.0.0, such packages would fail to load with "LoadLibrary + failure: The specified module could not be found". + * When building the bundled copy of oneTBB, RcppParallel no longer searches for hwloc, and so no longer tries to build the optional 'tbbbind' library. This fixes build failures on machines where a static hwloc library is diff --git a/R/zzz.R b/R/zzz.R index 54374e09..9637367a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -11,10 +11,23 @@ .tbbMallocProxyDllInfo <- NULL loadTbbLibrary <- function(name) { - # TBB is statically linked on Windows + + # On Windows, TBB is statically linked into RcppParallel.dll, but we + # still ship a stub tbb.dll for compatibility with packages linking via + # '-ltbb' (e.g. through StanHeaders). Such packages record a load-time + # dependency on 'tbb.dll', which the Windows loader can only resolve if + # we've already loaded it -- the library directory itself is not on the + # DLL search path. if (is_windows()) { - return(NULL) + + path <- file.path(tbbRoot(), paste0(name, ".dll")) + if (!file.exists(path)) + return(NULL) + + return(dyn.load(path, local = FALSE, now = TRUE)) + } + path <- tbbLibraryPath(name) if (is.null(path)) return(NULL)