How to link a library in Rtools on Windows?

63 views Asked by At

I am trying to use a library (Intel TBB) in my R package on Windows, but not sure how to write makevars.win.

I have Rtools installed, and there are the library under include:

C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\include\tbb

My makevars.win is

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) -ltbb
PKG_CXXFLAGS = -DARMA_64BIT_WORD=1
PKG_CPPFLAGS = -I../inst/include -DARMA_DONT_PRINT_OPENMP_WARNING=1 

but it errors.

g++ -std=gnu++17 -shared -s -static-libgcc -o quanteda.dll tmp.def RcppExports.o fcm.o index.o kwic.o pattern2fixed.o serialize.o tokens_chunk.o tokens_combine.o tokens_compound.o tokens_group.o tokens_lookup.o tokens_ngrams.o tokens_recompile.o tokens_replace.o tokens_restore.o tokens_segment.o tokens_select.o tokens_xptr.o utility.o -LC:/PROGRA~1/R/R-43~1.2/bin/x64 -lRlapack -LC:/PROGRA~1/R/R-43~1.2/bin/x64 -lRblas -ltbb -LC:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/RBuildTools/4.3/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-43~1.2/bin/x64 -lR
C:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\bin/ld.exe: cannot find -ltbb: No such file or directory
collect2.exe: error: ld returned 1 exit status

Would you tell me what is missing?

I tried manually adding -LC:\RBuildTools\4.3\x86_64-w64-mingw32.static.posix\include to makevars.win, but did not work...

1

There are 1 answers

0
Kohei Watanabe On

By replacing RBuildTools with rtools43 and adding -ltbb12 -fstack-protector to makevars.win, I could compile the package.

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) -ltbb12 -fstack-protector
PKG_CXXFLAGS = -DARMA_64BIT_WORD=1
PKG_CPPFLAGS = -I../inst/include -DARMA_DONT_PRINT_OPENMP_WARNING=1
g++ -std=gnu++17 -shared -s -static-libgcc -o quanteda.dll tmp.def RcppExports.o fcm.o index.o kwic.o pattern2fixed.o serialize.o tokens_chunk.o tokens_combine.o tokens_compound.o tokens_group.o tokens_lookup.o tokens_ngrams.o tokens_recompile.o tokens_replace.o tokens_restore.o tokens_segment.o tokens_select.o tokens_xptr.o utility.o -LC:/PROGRA~1/R/R-43~1.2/bin/x64 -lRlapack -LC:/PROGRA~1/R/R-43~1.2/bin/x64 -lRblas -ltbb12 -fstack-protector -LC:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64 -LC:/rtools43/x86_64-w64-mingw32.static.posix/lib -LC:/PROGRA~1/R/R-43~1.2/bin/x64 -lR
installing to C:/Users/watan/AppData/Local/R/win-library/4.3/00LOCK-quanteda/00new/quanteda/libs/x64
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (quanteda)