Skip to content

[Rcpp-devel] sourceCpp failing on windows whereas devtools::has_devel and devtools:::R works

6 messages · Romain Francois, Dirk Eddelbuettel, JJ Allaire

#
Hello,

On a windows machine where Rtools is installed and works, i.e. I get:
"C:/R/R-3.0.2/bin/i386/R" --vanilla CMD SHLIB foo.c

gcc -m32 -I"C:/R/R-30~1.2/include" -DNDEBUG    
-I"C:/R/R-3.0.2/library/Rcpp/include" 
-I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O3 -Wall  
-std=gnu99 -mtune=core2 -c foo.c -o foo.o
gcc -m32 -shared -s -static-libgcc -o foo.dll tmp.def foo.o 
C:/R/R-3.0.2/library/Rcpp/lib/i386/libRcpp.a 
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 
-Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/R/R-30~1.2/bin/i386 -lR
[1] TRUE


sourceCpp does not manage to find the tools correctly:
Error in sourceCpp(code = code, env = env, rebuild = rebuild, 
showOutput = showOutput,  :
   Error 1 occurred building shared library.

WARNING: The tools required to build C++ code for R were not found.

Please download and install the appropriate version of Rtools:

http://cran.r-project.org/bin/windows/Rtools/


Using devtools:::R however, I manage to compile the file correctly:
+ using namespace Rcpp;
+
+ // [[Rcpp::export]]
+ double foo(){
+        return 2;
+ }
+ '
"C:/R/R-3.0.2/bin/i386/R" --vanilla CMD SHLIB test.cpp

g++ -m32 -I"C:/R/R-30~1.2/include" -DNDEBUG     
-I"d:/RCompile/CRANpkg/extralibs64/local/include"  
-IC:/R/R-3.0.2/library/Rcpp/include   -O2 -Wall  -mtune=core2 -c 
test.cpp -o test.o
g++ -m32 -shared -s -static-libgcc -o test.dll tmp.def test.o 
C:/R/R-3.0.2/library/Rcpp/lib/i386/libRcpp.a 
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 
-Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/R/R-30~1.2/bin/i386 -lR


So perhaps we can borrow some wisdom out of devtools to make sourceCpp 
work. As one can expect, the code from sourceCpp that fails is these 
lines:

cmd <- paste(R.home(component = "bin"), .Platform$file.sep,
             "R ", "CMD SHLIB ", "-o ", shQuote(context$dynlibFilename),
             " ", ifelse(rebuild, "--preclean ", ""), 
shQuote(context$cppSourceFilename),
             sep = "")

Romain
_
platform       i386-w64-mingw32
arch           i386
os             mingw32
system         i386, mingw32
status
major          3
minor          0.2
year           2013
month          09
day            25
svn rev        63987
language       R
version.string R version 3.0.2 (2013-09-25)
nickname       Frisbee Sailing
[1] "0.10.5"
#
On 17 October 2013 at 09:04, romain at r-enthusiasts.com wrote:
| On a windows machine where Rtools is installed and works, i.e. I get:
[...] 
| sourceCpp does not manage to find the tools correctly:
[...] 
| > evalCpp( "1+1")
| 
| Error in sourceCpp(code = code, env = env, rebuild = rebuild, 
| showOutput = showOutput,  :
|    Error 1 occurred building shared library.
| 
| WARNING: The tools required to build C++ code for R were not found.
| 
| Please download and install the appropriate version of Rtools:
| 
| http://cran.r-project.org/bin/windows/Rtools/

Can you exclude local circumstances?  

This routine is about one year old, and very widely used including on
Windows. And including by us e.g. via win-builder and the CRAN builds as
sourceCpp() is now used for eg the unit testing. 

And it never failed in any of the uploads or tests I triggered. 

Dirk
#
So I took this as an excuse to bring my win7 machine at work to R 3.0.* and
to update Rtools. And with "everything current":

  R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
  Copyright (C) 2013 The R Foundation for Statistical Computing
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  
  R is free software and comes with ABSOLUTELY NO WARRANTY.
  You are welcome to redistribute it under certain conditions.
  Type 'license()' or 'licence()' for distribution details.
  
  R is a collaborative project with many contributors.
  Type 'contributors()' for more information and
  'citation()' on how to cite R or R packages in publications.
  
  Type 'demo()' for some demos, 'help()' for on-line help, or
  'help.start()' for an HTML browser interface to help.
  Type 'q()' to quit R.
  
  R> library(Rcpp)
  R> evalCpp("1+1")
  [1] 2
  R> 

So it works here too. For good measure I tested in Rgui and RStudio, 32 bit
and 64 bit.  All are fine.

Dirk
#
I think the reason Dirk's configuration worked is that he added Rtools to
the path during installation. If Romain didn't do this, then sourceCpp goes
looking for Rtools 2.15 or 2.16 (the initial development version for R 3.0)
and doesn't find it. I just committed a change that includes R 3.0 and R
3.1 in the whitelist of Rtools versions we know work correctly.

J.J.
On Thu, Oct 17, 2013 at 3:04 AM, <romain at r-enthusiasts.com> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131017/51c0a17e/attachment.html>
#
On 17 October 2013 at 10:49, JJ Allaire wrote:
| I think the reason Dirk's configuration worked is that he added Rtools to the
| path during installation. If Romain didn't do this, then sourceCpp goes looking

Even system-wide.  And I "fix" directories, so it is always

     c:/opt/R-current                       # no matter which R version
     c:/opt/Rtools
     c:/opt/Rlibrary
     c:/opt/RStudio
     ...


| for Rtools 2.15 or 2.16 (the initial development version for R 3.0) and doesn't
| find it. I just committed a change that includes R 3.0 and R 3.1 in the
| whitelist of Rtools versions we know work correctly.

That does sound like a likely culprit -- thanks!

Dirk
#
Le 2013-10-17 16:49, JJ Allaire a ?crit?:
Thanks JJ. I've applied the change to Rcpp11 too.

Indeed my client could not choose the option to change his PATH when 
using Rtools installer because of some windows admin rights #bs. There 
could have been other ways to fix it locally, and during the training 
yesterday, using Rstudio was just fine. I just did not like the idea of 
having Rtools installed, and usable (i.e. devtools could find it), but 
not being able to use it from sourceCpp.

Romain