rrcpprtools

How to install a source package with c++ code in R windows?


I have an R package with Rcpp code. Builds fine in any linux distribution. The problem is building it in windows. I have the following in my set-up

  1. R version 4.0.1 (2020-06-06)
  2. Windows 10 Pro version 1903
  3. Rtools 4.0 installed in C:\rtools40

This is the output of Rgui:

> utils:::menuInstallLocal()
Warning in untar2(tarfile, files, list, exdir, restore_times) :
  skipping pax global extended headers
* installing *source* package 'mansched' ...
** using staged installation
** libs
C:/PROGRA~1/R/R-40~1.1/etc/x64/Makeconf:244: warning: overriding commands for target `.m.o'
C:/PROGRA~1/R/R-40~1.1/etc/x64/Makeconf:237: warning: ignoring old commands for target `.m.o'
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c RcppExports.cpp -o RcppExports.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c assignPool.cpp -o assignPool.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c assignemp.cpp -o assignemp.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c assignmh.cpp -o assignmh.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c gethours.cpp -o gethours.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c getmin.cpp -o getmin.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c isreg.cpp -o isreg.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c isrf.cpp -o isrf.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c mhdb.cpp -o mhdb.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -I"C:/PROGRA~1/R/R-40~1.1/include" -DNDEBUG  -I'D:/Users/USER/Documents/R/win-library/4.0/Rcpp/include'        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c normemp.cpp -o normemp.o
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11  -shared -s -static-libgcc -o mansched.dll tmp.def RcppExports.o assignPool.o assignemp.o assignmh.o gethours.o getmin.o isreg.o isrf.o mhdb.o normemp.o -LC:/PROGRA~1/R/R-40~1.1/bin/x64 -lR
/usr/bin/sh: line 8: "C:/rtools40/mingw64/bin/"g++ -std=gnu++11 : No such file or directory
no DLL was created
ERROR: compilation failed for package 'mansched'
* removing 'D:/Users/USER/Documents/R/win-library/4.0/mansched'
Warning message:
In install.packages(files[tarballs], .libPaths()[1L], repos = NULL,  :
  installation of package ‘d:/Users/USER/Downloads/mansched-nocxx.tar.gz’ had non-zero exit status

The error /usr/bin/sh: line 8: "C:/rtools40/mingw64/bin/"g++ -std=gnu++11 : No such file or directory does not make sense since that directory exists.


Solution

  • I found my luck in devtools. I uploaded my package in github and installed using devtools::install_github("myuser/my_rcpp_package"). Using devtools, an R package with c++ code can be built without any issues.