title: Building R package with Rtools4.0 on Windows 10
body: <p>I am trying to build an <code>R</code> package using <a href="https://cran.r-project.org/bin/windows/testing/rtools40.html" rel="nofollow noreferrer">RTools4.0</a> on Windows 10 machine. My package needs the SBML C library and static libraries for SBML for building R packages on Window is provided by <code>RTools4.0</code> <a href="https://github.com/r-windows/rtools-packages" rel="nofollow noreferrer">link</a> </p>
  
  <p>I was able to successfully install <code>RTools4.0</code> and the additional SBML library. I checked that I have the header files for SBML in</p>
  
  <p><code>C:\rtools40\mingw64\include\sbml&gt;</code> and the <code>libsbml.a</code> file n</p>
  
  <p><code>C:\rtools40\mingw64\lib&gt;</code></p>
  
  <p><strong>Updated with latest information</strong></p>
  
  <p>My package builds successfully on Mac OSX (Mojave) (without <code>RTools4.0</code>), however I am facing issues with installing my package on Windows.</p>
  
  <p>The contents of my <code>Makevars.win</code> file are as follows:</p>
  
  <pre><code>CXX=clang++
  PKG_CPPFLAGS= -I/mingw$(WIN)/include/
  PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lsbml -lbz2 -lz -lxml2 -liconv -lws2_32
  </code></pre>
  
  <p>I am able to select <code>rtools40</code> and build the package using the following commands from within <code>RStudio</code></p>
  
  <pre><code>Sys.setenv(PATH = paste("C:/rtools40/mingw64/bin", Sys.getenv("PATH"), sep=";"))
  Sys.setenv(PATH = paste("C:/rtools40/mingw32/bin", Sys.getenv("PATH"), sep=";"))
  Sys.setenv(BINPREF = "C:/rtools40/mingw32/bin/")  
  devtools::install()
  </code></pre>
  
  <p>And the error I am getting is given below:</p>
  
  <pre><code>Installing Rcppsbml
  "C:/PROGRA~1/R/R-34~1.1/bin/x64/R" --no-site-file --no-environ --no-save  \
    --no-restore --quiet CMD INSTALL  \
    "C:/Users/sn248/Documents/GitHub/Rcppsbml"  \
    --library="C:/Users/sn248/Documents/R/win-library/3.4"  \
    --install-tests 
  
  * installing *source* package 'Rcppsbml' ...
  ** libs
  
  *** arch - i386
  C:/rtools40/mingw32/bin/g++  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I/mingw32/include/ -I"C:/Users/sn248/Documents/R/win-library/3.4/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c convertReactions.cpp -o convertReactions.o
  C:/rtools40/mingw32/bin/g++  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I/mingw32/include/ -I"C:/Users/sn248/Documents/R/win-library/3.4/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c printSBML.cpp -o printSBML.o
  C:/rtools40/mingw32/bin/g++  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I/mingw32/include/ -I"C:/Users/sn248/Documents/R/win-library/3.4/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c rcpp_hello.cpp -o rcpp_hello.o
  C:/rtools40/mingw32/bin/g++ -shared -s -static-libgcc -o Rcppsbml.dll tmp.def convertReactions.o printSBML.o rcpp_hello.o -LC:/PROGRA~1/R/R-34~1.1/bin/i386 -lRlapack -LC:/PROGRA~1/R/R-34~1.1/bin/i386 -lRblas -lgfortran -lm -lquadmath -lsbml -lbz2 -lz -lxml2 -liconv -lws2_32 -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-34~1.1/bin/i386 -lR
  installing to C:/Users/sn248/Documents/R/win-library/3.4/Rcppsbml/libs/i386
  
  *** arch - x64
  C:/rtools40/mingw32/bin/g++  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I/mingw64/include/ -I"C:/Users/sn248/Documents/R/win-library/3.4/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c convertReactions.cpp -o convertReactions.o
  C:/rtools40/mingw32/bin/g++  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I/mingw64/include/ -I"C:/Users/sn248/Documents/R/win-library/3.4/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c printSBML.cpp -o printSBML.o
  C:/rtools40/mingw32/bin/g++  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I/mingw64/include/ -I"C:/Users/sn248/Documents/R/win-library/3.4/Rcpp/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c rcpp_hello.cpp -o rcpp_hello.o
  C:/rtools40/mingw32/bin/g++ -shared -s -static-libgcc -o Rcppsbml.dll tmp.def convertReactions.o printSBML.o rcpp_hello.o -LC:/PROGRA~1/R/R-34~1.1/bin/x64 -lRlapack -LC:/PROGRA~1/R/R-34~1.1/bin/x64 -lRblas -lgfortran -lm -lquadmath -lsbml -lbz2 -lz -lxml2 -liconv -lws2_32 -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-34~1.1/bin/x64 -lR
  C:/PROGRA~1/R/R-34~1.1/bin/x64/Rlapack.dll: file not recognized: file format not recognized
  collect2.exe: error: ld returned 1 exit status
  no DLL was created
  ERROR: compilation failed for package 'Rcppsbml'
  * removing 'C:/Users/sn248/Documents/R/win-library/3.4/Rcppsbml'
  * restoring previous 'C:/Users/sn248/Documents/R/win-library/3.4/Rcppsbml'
  Error: Command failed (1)
  </code></pre>
  
  <p>I sort of understand why I am getting the error because even for <code>x64</code>, the 32-bit compiler <code>C:/rtools40/mingw32/bin/g++</code> is being used. I don't know how to write the options to choose the correct compiler for <code>x64</code> since <code>BINPREF</code> only takes 1 directory as an input.</p>
  
  <p>My <code>R.version</code> information is given below:</p>
  
  <pre><code>&gt; R.version
                 _                           
  platform       x86_64-w64-mingw32          
  arch           x86_64                      
  os             mingw32                     
  system         x86_64, mingw32             
  status                                     
  major          3                           
  minor          4.1                         
  year           2017                        
  month          06                          
  day            30                          
  svn rev        72865                       
  language       R                           
  version.string R version 3.4.1 (2017-06-30)
  nickname       Single Candle 
  </code></pre>
  
  <p>The entire package code can be found at - <a href="https://github.com/sn248/Rcppsbml" rel="nofollow noreferrer">https://github.com/sn248/Rcppsbml</a></p>
  
  <p>As seen from above, I am using <code>R-3.4.1</code> (which I can't update for now due to non-technical issues) and another version of Rtools (appropriate for <code>R-3.4.1</code>) also installed on my machine. </p>
  
  <p>My questions are as follows:</p>
  
  <p>Is there anyway to specify using <code>rtools40</code> while building the package using <code>RStudio</code>'s <code>Clean and Rebuild</code> option? </p>
  
  <p>Even if I am able to install this library on my machine, will it work for <code>CRAN</code> checks? </p>
  
  <p>Any help here would be very much appreciated, thanks!!</p>