Rcpp inline package error in compileCode

主宰稳场 提交于 2019-12-11 03:09:03

问题


I have R installed along with these two packages Rcpp and inline. (I am doing a project that consists of speeding up a painfully slow program in R and I decided to use Rcpp)...I know I am doing something wrong...probably missing a step but i cannot figure it out. Props to Dirk if you're reading this! Thanks for Rcpp and the brand new inline package pdf but...it's still not running. Please note that I'm a newbie. As stated before I cleaned out all other packages and only R is installed with Rcpp and inline (of course I have c++ installed as well).

    library(Rcpp)
    library(inline)
    x<-as.numeric(1:10)
    n<-as.integer(10)
    code<-"
    integer i 
    do 1 i=1, n(1)
    1 x(i)=x(i)**3
    "
    cubefn<-                       cfunction(signature(n="integer",x="numeric"),code,convention=".Fortran")
     ERROR(s) during compilation: source code errors or   compiler      configuration errors!
                Program source:
      1: #include <R.h>
      2: 
      3: 
      4: extern "C" {
      5:   void filef2424e34d61 ( int * n, double * x );
      6: }
      7: 
      8: void filef2424e34d61 ( int * n, double * x ) {
      9: 
     10: integer i
     11: do 1 i=1, n(1)
     12: 1 x(i)=x(i)**3
     13: 
     14: }
    Error in compileCode(f, code, language, verbose) : 
      Compilation ERROR, function(s)/method(s) not created! 
    In addition: Warning message:
    running command 'C:/R/R-2.15.2/bin/x64/R CMD SHLIB filef2424e34d61.cpp 2> filef2424e34d61.cpp.err.txt' had status 1 

If it is the construction of a package skeleton missing: i tried the simple rcpp_hello_world() example:

    rcpp_hello_world <- function(){

    .Call( "rcpp_hello_world", PACKAGE = "mypackage" )
    }

    Folder PATH listing for volume OS
    Volume serial number is 769C-A616
    C:.

The rest was a long list of odd symbols but what I could read was the name of c++ projects I have, I didn't include them as it would be too lengthy

    rcpp_hello_world <-function(){

    .Call("rcpp_hello_world",PACKAGE="mypackage")

    }

    rcpp_hello_world()

    Error in .Call("rcpp_hello_world", PACKAGE = "mypackage") : 
      "rcpp_hello_world" not available for .Call() for package "mypackage"

Anything would help please, also I have linux installed as well so if that is a better option please do tell. I am open to anything right now, the slightest progress makes is a delight


回答1:


Do you actually have a Fortran compiler installed?

If you don't, or you don't know, try your Linux box. R on Windows must be able to compile source packages if you want to build with Rcpp and inline. A good quick test is to try something like

R> myroot <- cppFunction('double myroot(double x) { return ::sqrt(x); }')
R> myroot(16)
[1] 4
R> 

or equivalently via inline (where rcpp is a wrapper for the cxxfunction(..., plugin="Rcpp") call, you need the most recent inline package for that)

R> myroot2 <- rcpp(signature(xs="numeric"), 
+                  body='double x=as<double>(xs); return wrap(::sqrt(x));')
R> myroot2(16)
[1] 4
R> 

If this does not work, read up on the R basics of installing Rtools for Windows etc. We have a few additional notes in the Rcpp FAQ as well.



来源:https://stackoverflow.com/questions/14939474/rcpp-inline-package-error-in-compilecode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!