title: Error installing and running rcpp
body: <p>I'm pretty new to R so apologies for a stupid question. I'm trying to get rcpp running but I'm stuck in an endless loop of R asking me to re-install RTools.</p>
  
  <p>I broadly followed the code in <a href="http://www.r-bloggers.com/user2013-the-rcpp-tutorial/" rel="noreferrer">this blog post</a>, although first time off I installed everything by hand &amp; I've subsequently re-installed everything a few times over. I'm running Windows 7, R version 3.1.2, R Studio Version 0.98.1091 (not that this should matter much) and RTools 3.1.</p>
  
  <p>An edited highlight of what my console looks like is as follows:</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; library(installr) 
  Welcome to installr version 0.15.3...
  
  &gt; install.Rtools()
  Loading required package: devtools
  No need to install Rtools - You've got the relevant version of Rtools installed
  
  &gt; find_rtools()
  [1] TRUE
  
  &gt; library(Rcpp)
  &gt; evalCpp("1+1")
  
  Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput,  :
  Error 65535 occurred building shared library.
  </code></pre>
  
  <p>At which point a dialog box pops up saying:</p>
  
  <blockquote>
    <p>Install Build Tools
    Compiling C/C++ code for R requires installation of additional build tools.
    Do you want to install the additional tools now?</p>
  </blockquote>
  
  <p>And then I get directed to download and re-install RTools 3.1 from cran all over again.</p>
  
  <p>I've seen that this can be an issue with the PATH variable but I've tried various things including:</p>
  
  <ol>
  <li>Nothing (extra) in the PATH variable</li>
  <li>Including both references to R (C:\Program Files\R\R-3.1.2\bin\x64) and RTools (C:\RBuildTools\3.1\bin;C:\RBuildTools\3.1\gcc-4.6.3\bin;) in the PATH. Once with RTools first, once with R first</li>
  <li>Including just a reference to RTools in the PATH as the initial install file directed me to do.</li>
  </ol>
  
  <p>Any ideas on things to try would be gratefully accepted!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Following Dirk's comment it looks like I might have a problem with how RTools is installed. I've followed the instructions from several blogs / tutorials on how to install RTools; all to no avail (yet!)</p>
  
  <p><a href="https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows" rel="noreferrer">This GitHub page</a> gives some instructions on how install and check that the installation has worked. I've followed all the checks (see below for copy of the console) and it looks like I have a working install of RTools, but when I try to run <code>evalCPP()</code> again I get the same error as before directing me to install RTools.</p>
  
  <pre class="lang-r prettyprint-override"><code>&gt; Sys.getenv('PATH')
  [1] "C:\\Program Files\\R\\R-3.1.2\\bin\\x64;C:\\RTools\\bin;C:\\RTools\\gcc-4.6.3\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Enterprise Vault\\EVClient\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\100\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\PrivateAssemblies\\;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\;C:\\Program Files\\Microsoft\\Web Platform Installer\\;C:\\Program Files (x86)\\Microsoft SDKs\\TypeScript\\1.0\\;C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\"
  Warning message:
  printing of extremely long output is truncated
  
  &gt; system('g++ -v')
  Using built-in specs.
  COLLECT_GCC=C:\RTools\GCC-46~1.3\bin\G__~1.EXE
  COLLECT_LTO_WRAPPER=c:/rtools/gcc-46~1.3/bin/../libexec/gcc/i686-w64-mingw32/4.6.3/lto-wrapper.exe
  Target: i686-w64-mingw32
  Configured with: /data/gannet/ripley/Sources/mingw-test3/src/gcc/configure --host=i686-w64-mingw32 --build=x86_64-linux-gnu --target=i686-w64-mingw32 --with-sysroot=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --prefix=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/mingw32 --with-gmp=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpfr=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --with-mpc=/data/gannet/ripley/Sources/mingw-test3/mingw32mingw32/prereq_install --disable-shared --enable-static --enable-targets=all --enable-languages=c,c++,fortran --enable-libgomp --enable-sjlj-exceptions --enable-fully-dynamic-string --disable-nls --disable-werror --enable-checking=release --disable-win32-registry --disable-rpath --disable-werror CFLAGS='-O2 -mtune=core2 -fomit-frame-pointer' LDFLAGS=
  Thread model: win32
  gcc version 4.6.3 20111208 (prerelease) (GCC) 
  
  &gt; system('where make')
  C:\Rtools\bin\make.exe
  </code></pre>
  
  <p>I've also had a look at <a href="http://cran.r-project.org/doc/manuals/r-release/R-admin.html#The-Windows-toolset" rel="noreferrer">Appendix D of R Installation and Admin</a>. I can't see anything in here I've not already tried except for <a href="http://cran.r-project.org/doc/manuals/r-release/R-admin.html#The-MinGW_002dw64-toolchain" rel="noreferrer">section D.4</a> which implies I might need to rebuild rcpp from source using my installed RTools. I don't have time to do this right away but will give it a try unless people say this route is not worth my time.</p>
  
  <p><strong>EDIT v2</strong></p>
  
  <p>So I tried building rcpp from source ... and that didn't work either. I downloaded both the package source and windows binaries from <a href="http://cran.r-project.org/web/packages/Rcpp/index.html" rel="noreferrer">the CRAN Rcpp package page</a>. In the R console I now get:</p>
  
  <pre><code>&gt; install.packages(pkgs = "C:/Rcpp_0.11.4.tar.gz", repos = NULL, contriburl = NULL, type = "source", verbose = TRUE)
  Installing package into ‘C:/Users/james.macadie/Documents/R/win-library/3.1’
  (as ‘lib’ is unspecified)
  system (cmd0): C:/PROGRA~1/R/R-31~1.2/bin/x64/R CMD INSTALL
  Warning in install.packages :
    package ‘C:/Rcpp_0.11.4.tar.gz’ is not available (for R version 3.1.2)
  </code></pre>
  
  <p>I guess my active questions now boil down to:</p>
  
  <ul>
  <li>Reading the whole of the post above can anyone tell me how to fix things so it just works? Or, failing that...</li>
  <li>What tests can I run to check I really do have Rtools installed correctly? Everything I have found on the internet suggests I do: <code>system('where make')</code> etc. However, the evidence of being unable to run <code>evalCpp</code> or other rccp functions suggests I don't.</li>
  <li>What am I doing wrong when building from source? Should I try the command line option?</li>
  </ul>
  
  <p><strong>EDIT v3</strong></p>
  
  <p>Running <code>evalCpp</code> with <code>showOutput= TRUE</code> and <code>verbose = TRUE</code> I think I've tracked the error back to <code>R CMD SHLIB</code> not working. I followed <a href="http://mcglinn.web.unc.edu/blog/linking-c-with-r-in-windows/" rel="noreferrer">this blog</a>, which shows how to work with the command line R directly. However when I get to the line <code>R CMD SHLIB sequence_examples.c</code> the execution just skips straight to the next command line without doing anything, generating any files in the directory or throwing any errors. I tried running the <code>--help</code> options at the command line but get the same sort of error:</p>
  
  <pre><code>C:\Users\james.macadie&gt; R --help
  
  
  Or: R CMD command args
  
  where 'command' is one of:
    INSTALL  Install add-on packages
    REMOVE   Remove add-on packages
    SHLIB    Make a DLL for use with dynload
    BATCH    Run R in batch mode
    build    Build add-on packages
    check    Check add-on packages
    Rprof    Post process R profiling files
    Rdconv   Convert Rd format to various other formats
    Rdiff    difference R output files
    Rd2pdf   Convert Rd format to PDF
    Rd2txt   Convert Rd format to pretty text
    Stangle   Extract S/R code from vignette
    Sweave    Process vignette documentation
    config   Obtain configuration information about R
    open     Open a file via Windows file associations
    texify   Process a latex file
  
  Use
    R CMD command --help
  for usage information for each command.
  
  
  C:\Users\james.macadie&gt; R CMD SHLIB --help
  
  C:\Users\james.macadie&gt;
  </code></pre>
  
  <p>N.B. for people reading the earlier code samples higher up this post I have changed a few things since those code snapshots:</p>
  
  <ul>
  <li>I've installed R directly into C:\R. It used to be in C:\Program Files\R\ but as has been suggested file paths with spaces in can cause problems</li>
  <li>I'm referencing Rtools under C:\Rtools\ and not C:\RBuildTools\</li>
  </ul>
  
  <p>Thanks for any suggestions, as ever</p>