Skip to content

Commit ec75f86

Browse files
committed
don't emit -ltbb when no tbb was installed
The Windows branch of tbbLdFlags() named the TBB libraries unconditionally, dropping the file.exists() guard the previous stub-based code had. On a build that fell back to tinythread -- configure.R sets TBB_ENABLED = FALSE only there, when cmake is missing and TBB_LIB is unset -- RcppParallelLibs() then emitted -L<libs> -lRcppParallel -L<lib> -ltbb -ltbbmalloc for libraries that were never built or shipped, so a downstream package would fail to link with "cannot find -ltbb". CxxFlags() correctly reports -DRCPP_PARALLEL_USE_TBB=0 in that configuration, so the package is not even using TBB. Name them only when TBB is enabled and the library actually resolves. Also drop an unverified aside from NEWS: Rtools42 and Rtools45 are confirmed to ship cmake, Rtools40 was not checked.
1 parent a54538d commit ec75f86

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
against. Building it ourselves gives every platform the same oneTBB and makes
1818
the ABI a property of RcppParallel. `TBB_LIB` / `TBB_INC` are still honoured
1919
for anyone supplying their own build. This requires cmake, which Rtools has
20-
provided since Rtools42; toolchains without it (e.g. Rtools40) continue to
21-
use the tinythread fallback.
20+
shipped since Rtools42; toolchains without one continue to use the tinythread
21+
fallback.
2222

2323
* As a consequence, `RcppParallel::RcppParallelLibs()` now emits `-ltbb` and
2424
`-ltbbmalloc` on Windows, in addition to `-lRcppParallel` (which remains

R/tbb.R

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,23 @@ tbbLdFlags <- function() {
9494
if (is_windows()) {
9595

9696
libsPath <- archSystemFile("libs")
97-
tbbPath <- tbbLibraryPath()
98-
99-
fmt <- "-L%s -lRcppParallel -L%s -l%s -l%s"
100-
return(sprintf(
101-
fmt,
102-
asBuildPath(libsPath),
103-
asBuildPath(tbbPath),
104-
TBB_NAME,
105-
TBB_MALLOC_NAME
106-
))
97+
ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libsPath))
98+
99+
# only name the TBB libraries when there are TBB libraries to name: a
100+
# build that fell back to tinythread ships none, and asking the linker
101+
# for them would fail the downstream build outright
102+
if (TBB_ENABLED && !is.null(tbbLibraryPath("tbb"))) {
103+
fmt <- "%s -L%s -l%s -l%s"
104+
ldFlags <- sprintf(
105+
fmt,
106+
ldFlags,
107+
asBuildPath(tbbLibraryPath()),
108+
TBB_NAME,
109+
TBB_MALLOC_NAME
110+
)
111+
}
112+
113+
return(ldFlags)
107114

108115
}
109116

0 commit comments

Comments
 (0)