How to Fix Compilation Failure on Windows

Summary

To install RAnEn on Windows, please check the following requirements:

  • R version is greater than or equal to 3.3.0;
  • The matching version of R tools is installed;

Details

If you’ve got the following error on Windows when installing the RAnEn package:

> install.packages("https://github.com/Weiming-Hu/AnalogsEnsemble/raw/master/RAnalogs/releases/RAnEn_latest.tar.gz", repos = NULL)
trying URL 'https://github.com/Weiming-Hu/AnalogsEnsemble/raw/master/RAnalogs/releases/RAnEn_latest.tar.gz'
Content type 'application/octet-stream' length 114102 bytes (111 KB)
downloaded 111 KB

* installing *source* package 'RAnEn' ...

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs

*** arch - i386
g++ -m32 -std=c++0x -I"C:/Users/student/DOCUME~1/R/R-32~1.2/include" -DNDEBUG    -I"C:/Users/student/Documents/R/R-3.2.2/library/Rcpp/include" -I"C:/Users/student/Documents/R/R-3.2.2/library/BH/include" -I"d:/RCompile/r-compiling/local/local320/include"  -fopenmp   -O2 -Wall  -mtune=core2 -c AnEn.cpp -o AnEn.o
sh: g++: command not found
make: *** [C:/Users/student/DOCUME~1/R/R-32~1.2/etc/i386/Makeconf:189: AnEn.o] Error 127
Warning: running command 'make -f "Makevars.win" -f "C:/Users/student/DOCUME~1/R/R-32~1.2/etc/i386/Makeconf" -f "C:/Users/student/DOCUME~1/R/R-32~1.2/share/make/winshlib.mk" CXX='$(CXX1X) $(CXX1XSTD)' CXXFLAGS='$(CXX1XFLAGS)' CXXPICFLAGS='$(CXX1XPICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX1XLDFLAGS)' SHLIB_LD='$(SHLIB_CXX1XLD)' SHLIB="RAnEn.dll" OBJECTS="AnEn.o Analogs.o Array4D.o Forecasts.o Observations.o Parameters.o RcppExports.o Rinterface.o SimilarityMatrices.o StandardDeviation.o Stations.o Times.o"' had status 2
ERROR: compilation failed for package 'RAnEn'
* removing 'C:/Users/student/Documents/R/R-3.2.2/library/RAnEn'
Warning in install.packages :
  running command '"C:/Users/student/DOCUME~1/R/R-32~1.2/bin/x64/R" CMD INSTALL -l "C:\Users\student\Documents\R\R-3.2.2\library" "C:/Users/student/AppData/Local/Temp/Rtmpo7NEWg/downloaded_packages/RAnEn_latest.tar.gz"' had status 1
Warning in install.packages :
  installation of package ‘C:/Users/student/AppData/Local/Temp/Rtmpo7NEWg/downloaded_packages/RAnEn_latest.tar.gz’ had non-zero exit status

Two things you might want to check.

First, whether you have installed the correct version of Rtools that matches your R version.

Every time you open R, you will see your R version information. Alternatively, you can check your R version by running the following command in an R session:

> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.2.2

For example, here I’m having R version 3.2.2. However, the minimum R version requirement is 3.3.0. Therefore, I decided to update to the current latest R version 3.5.1. To update to a newer version, it is a good practice to manually delete the older version. For my case, my older R is at the default location, C:\Program Files\R\R-3.2.2. I executed the program unins000.exe in the folder to uninstall the older version. Then I can safely install the newer version without worrying about having multiple versions of R installed.

However, it looks like RStudio does not automatically detect the updated version of R. You can inspect which R is RStudio using by typing the following command in an R session:

> .libPaths()
[1] "C:/Users/student/Documents/R/R-3.2.2/library"

Looks like in my case RStudio is still using another R that is installed in a non-conventional place. I went ahead and delete that R by running the uninstall program. Then when I reopen RStudio, it automatically finds the latest R that I’ve installed earlier.

If you check the Rtools table, I should be installing Rtools35.exe for compatibility reasons. Please install the matching version Rtools for your R and choose to add it to your PATH during the installation. I’ll come back to this afterwards and this is very convenient and helpful. The above should resolve part of the problem.

Second, whether you have chosen to add the Rtools path to your system PATH when you were installing Rtools, and whether you have restarted your Windows in order for PATH modification to have effect.

Adding Rtools to your system PATH variable enables the system to find tools during execution. To check whether you have added the Rtools path to your system environment variable PATH, you need to open up the system environment variable dialogue (Google it if you don’t know how to find it. It should be straightforward.). Your Path should contains something like below:

C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\Rtools\bin;<more paths>

Finally, restart a R session and try installing the package again. If problems remains, please open a ticket.

Thank you.

Weiming Hu

Comments