Closed
Description
Compiling on MacOS without the -undefined dynamic_lookup
linker flag reveals an undefined symbol. You can test this like so:
sed -i.bak 's/-undefined dynamic_lookup//g' $(R RHOME)/etc/Makeconf
And then installing from source will fail:
** configured file: 'R/tbb-autodetected.R.in' => 'R/tbb-autodetected.R'
*** configured file: 'src/install.libs.R.in' => 'src/install.libs.R'
*** configured file: 'src/Makevars.in' => 'src/Makevars'
** finished configure for package 'RcppParallel'
** libs
using C++ compiler: ‘Apple clang version 14.0.0 (clang-1400.0.29.202)’
using SDK: ‘’
(tbb) Building TBB using bundled sources ...
OS: macos
arch=intel64
compiler=clang
runtime=cc14.0.0_os12.7.2
tbb_build_prefix=macos_intel64_clang_cc14.0.0_os12.7.2
work_dir=/private/var/folders/qv/pdh5wsgn0lq3dp77zj602b5c0000gn/T/RtmpXzRtgl/R.INSTALL3d205139f0cb/RcppParallel/src/build/macos_intel64_clang_cc14.0.0_os12.7.2_release
(tbb) TBB compilation finished successfully.
clang++ -arch x86_64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/opt/R/x86_64/include -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fPIC -falign-functions=64 -Wall -g -O2 -c init.cpp -o init.o
clang++ -arch x86_64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/opt/R/x86_64/include -std=gnu++11 -DRCPP_PARALLEL_USE_TBB=1 -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fPIC -falign-functions=64 -Wall -g -O2 -c options.cpp -o options.o
clang++ -arch x86_64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/x86_64/lib -o RcppParallel.so init.o options.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Undefined symbols for architecture x86_64:
"tbb::interface7::internal::task_arena_base::internal_max_concurrency(tbb::interface7::task_arena const*)", referenced from:
_defaultNumThreads in options.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [RcppParallel.so] Error 1
ERROR: compilation failed for package ‘RcppParallel’
This is important when cross compiling (for example on p3m), otherwise the resulting binary cannot be loaded.
Metadata
Metadata
Assignees
Labels
No labels
Activity
eddelbuettel commentedon Jan 2, 2024
Can you put a PR together, and better yet, test it in the appropriate setting (i.e. with such cross-compilation) ?
kevinushey commentedon Jan 2, 2024
The problem here, I suspect, is that we don't explicitly link to libtbb; instead, we just try to dynamically load it when RcppParallel is loaded. This happens here:
RcppParallel/R/zzz.R
Lines 13 to 42 in 6f81716
We could probably set
PKG_LIBS
in some appropriate way for the "embedded" TBB case as well?RcppParallel/src/Makevars.in
Lines 14 to 17 in 6f81716
The complication here is that we don't move the library to its final install location until
install.libs.R
is invoked, and that happens after the linker step...eddelbuettel commentedon Jan 2, 2024
Also for what it is worth, when I am building 'water tight' packages for r2u I have to add libtbb-dev (or libtbb2-dev on 22.04) to the build-dependencies so that the shared linker-derived actual dependencies can be computed. So we do kinda sorta have a dependency on libtbb.
jeroen commentedon Jan 2, 2024
@kevinushey setting PKG_LIBS to link to the bundled libtbb would probably solve the build for RcppParallel itself. If I look at the build log on Windows, it does seem to do this already (
-Ltbb/build/lib_release -ltbb -ltbbmalloc
), so perhaps this can be mimicked for macos.In order to also fix packages that use
LinkingTo: RcppParallel
and subsequently are calling libtbb functions, we need to make sureRcppParallel::LdFlags()
also gives-L{path-to-RcppParallel}/lib -ltbb -ltbb_malloc
when RcppParalllel was built with the bundled libtbb.Alternatively, we could probably provide a static libtbb for MacOS via CRAN, so that you don't need the bundled one...