G++ Compile Error With R Package

Hi all,

I’m trying to install an R package on my windows 10 PC that includes Rstan. I did not build the package myself (it was built on mac). Though the package installs fine on mac:

devtools::install_github(“ColumbiaCDS/DEEPEst”,force = TRUE)

I get this output on PC:

C:/RBuildTools/3.5/mingw_32/bin/g++ -m32g -std=c++1y -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"…/inst/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -I"C:/Users/np2730/Documents/R/win-library/3.6/BH/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/rstan/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/StanHeaders/include" -O3 -Wno-unused-variable -Wno-unused-function -c RcppExports.cpp -o RcppExports.o
g++.exe: error: unrecognized command line option ‘-m32g’
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:215: RcppExports.o] Error 1
ERROR: compilation failed for package ‘DEEPEst’

I believe this issue has something to do with the compiler being used: on Mac, where the installation works fine, it mentions clang as the compiler instead of g++. I know practically nothing about C, so any insight anyone has would be really appreciated. I’m happy to provide any other information that I might have left out. I’m using R version 3.6.1 and rstan version 2.19.2.

You need a space in your ~/.R/Makevars.win file before the g, but actually you should just omit the debug info by putting -g0.

Thanks for responding!

I’m sorry if I’m missing something–I can’t find an ~/.R/Makevars.win file. I found a makevars.win file in ~/src/Makevars.win file–here’s the text:

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG

CXX_STD = CXX14

all: $(SHLIB)

clean:
		RM -rf *.so *.o

.phony: all clean

Which g are you referring to that I should put a space in front of?

Thanks again for helping!

That is the Makevars file for rstanarm. I would just delete it and then it might work.

Thank you for your help! Actually I found ~/.R/Makevars.win file. I add a space before the g and the error message become

g++.exe: error: g: No such file or directory.

Do you know what happen here?

If you are going to have a ~/.R/Makevars.win file, it should be generated by


but I would just delete it.

Thanks again for your help! Really appreciate it.

I did what this page told me to do and got the following error message when I run “install.packages(“rstan”, type = “source”)”

g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"…/inst/include" -I"." -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/Users/natha/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/natha/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/natha/Documents/R/win-library/3.6/BH/include" -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include" -O3 -march=native -c sparse_extractors.cpp -o sparse_extractors.o
sh: g++: command not found

make: *** [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:215: sparse_extractors.o] Error 127
ERROR: compilation failed for package ‘rstan’

  • removing ‘C:/Users/natha/Documents/R/win-library/3.6/rstan’
    Warning in install.packages :

It seems I still have problems in g++

When I deleted the ~/.R/Makevars.win file and installed the RStan package again, I got the following error message

Error in .shlib_internal(args) :
C++14 standard requested but CXX14 is not defined

  • removing ‘C:/Users/natha/Documents/R/win-library/3.6/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

You might try

pkgbuild::with_build_tools(install.packages("rstan", type = "source"))

with that Makevars.win file.

The error message is as following:

g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"…/inst/include" -I"." -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/Users/natha/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/natha/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/natha/Documents/R/win-library/3.6/BH/include" -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include" -march=native -O3 -march=native -c sparse_extractors.cpp -o sparse_extractors.o
sh: g++: command not found

make: *** [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:215: sparse_extractors.o] Error 127
ERROR: compilation failed for package ‘rstan’

  • removing ‘C:/Users/natha/Documents/R/win-library/3.6/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in
‘C:\Users\natha\AppData\Local\Temp\Rtmpw1Z9K5\downloaded_packages’

OK, you may need to put a full path to wherever g++ is, which is something like C:/Rtools/mingw_64/bin/g++.

Thank you so much for your help!! Would you like to be more specific that where should I put this line on? I am so sorry about my limit knowledge in CS.

Put it in the ~/.R/Makefiles.win file like

CXX14 = C:/Rtools/mingw_64/bin/g++

The error message dose not change.

Where is Rtools installed?

C:\Rtools

The Rstan package works well. I test with my codes. But it has problem install the DEEPest package we built based on RStan. And this package works well in MAC.

Besides I am able to install both RStan and RStanarm using “install.package” in RStudio. However I can’t use “devtools::install_github” to install RStanarm and the error message is above. g++: command not found