16

I am using Rstudio to create a package, and exploring the use of the Rcpp package to gain access to C++ code, however, when trying to build the package, and error is being thrown as follows:

fatal error: Rcpp.h: No such file or directory

Inline C++ code compiles fine, its only when considering standalone C++ files in the src folder, obviously referring to the #include <Rcpp.h> directive at the head of the .cpp file.

I think it may have something to do with environment variables, does anyone know what the correct configuration is and how to fix for Rstudio operating in an Ubuntu 12.04 LTS environment?

The commands sourceCpp('./src/xyz.cpp') execute as to be expected, the error is being thrown when Build and Reload is executed from within the RStudio IDE.

Nicholas Hamilton
  • 10,044
  • 6
  • 57
  • 88

4 Answers4

27

It is hard to say without having the package available. I guess you miss:

LinkingTo: Rcpp

in your DESCRIPTION file.

Romain Francois
  • 17,432
  • 3
  • 51
  • 77
  • 1
    Thanks after adding that, and creating a few symlinks to Rcpp installation directories, problem fixed. – Nicholas Hamilton Apr 28 '13 at 09:39
  • You should **not** need any symlinks, and doing so liberally will most likely create problems for your afterwards. Also: try `Rcpp.package.skeleton()` and the resulting package and compare. – Dirk Eddelbuettel Apr 28 '13 at 12:25
8

Did you by chance start with 'Create a package' in RStudio? If so, are you aware that you may have missed its sibbling option 'Create a package w/ Rcpp' ?

See the page on Using Rcpp with RStudio site for details, and particularly the final section on package building.

Also note that we wrote an entire vignette on using Rcpp with your own packages so I suggest you have a look at that too.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Hi Dirk, thanks for the above, it seems I am now getting another strange error when trying to use useDynLib(MYPACKAGE), reporting an undefined reference to `dgetrf_', any idea? – Nicholas Hamilton Apr 28 '13 at 15:30
  • No, I have no idea as you *insist on not posting code*. Send a *reproducible* example to rcpp-devel, please. – Dirk Eddelbuettel Apr 28 '13 at 15:34
  • Its not like that, I was just in the process of putting together a MWE, my package has ALOT of stuff in it, making it hard other than creating an effectively empty project. Anyway, turns out the culprit was the RcppArmadillo package, specifically, calling the determinant function for some reason, not sure why. – Nicholas Hamilton Apr 29 '13 at 00:03
1

I encountered this same symptom (Rcpp.h: No such file or directory) when trying to install the "xml2" package on an Ubuntu 14 system. In my case the root cause appeared to be a bad installation of package "Rcpp". Some of the files were there (Rcpp/libs) but others were not (Rcpp/include). I am not sure how the system got into this state but I suspect an installation of that package terminated part way through. Re-installing package "Rcpp" cleared up the issue for me.

gcbenison
  • 11,723
  • 4
  • 44
  • 82
1

This is because your GCC has been updated, and it is different than the one you had when you installed R. I had the same problem.

I removed the package "Rccp" by using:

remove.packages("Rcpp")

Then you need to install it again. Just run:

source("https://bioconductor.org/biocLite.R")
biocLite("Rcpp")
mpourreza
  • 177
  • 1
  • 1
  • 15