使用RStudio在R包中编译Rcpp代码时出错

时间:2022-12-07 12:44:37

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:

我正在使用Rstudio创建一个包,并探索如何使用Rcpp包来访问c++代码,但是,在尝试构建包时,出现了以下错误:

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

致命错误:Rcpp。h:没有这样的文件或目录

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.

内联c++代码编译得很好,只有在考虑src文件夹中的独立c++文件时才会这样,显然,它指的是#include 指令在.cpp文件的头部。 。h>

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?

我认为这可能与环境变量有关,有人知道什么是正确的配置,以及如何在Ubuntu 12.04 LTS环境中修复Rstudio操作吗?

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.

命令sourceCpp('./src/xyz.cpp')按预期执行,当构建和重新加载从RStudio IDE中执行时,将抛出错误。

4 个解决方案

#1


16  

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

没有现成的包装很难说。我猜你小姐:

LinkingTo: Rcpp

in your DESCRIPTION file.

在你的描述文件。

#2


7  

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' ?

你是否有机会在RStudio中“创建一个软件包”?如果是的话,您是否意识到您可能错过了它的sibbling选项“创建一个w/ Rcpp包”?

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

有关详细信息,请参阅Rcpp与RStudio站点的使用页面,特别是关于包构建的最后一节。

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.

还要注意的是,我们已经写了一篇关于在您自己的包中使用Rcpp的文章,所以我建议您也看一下这篇文章。

#3


0  

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.

我遇到了同样的症状(Rcpp)。h:没有这样的文件或目录)当尝试在Ubuntu 14系统上安装“xml2”包时。在我的情况下,根本原因似乎是安装“Rcpp”的糟糕安装。有些文件在那里(Rcpp/libs),而另一些不在那里(Rcpp/include)。我不确定系统是如何进入这种状态的,但是我怀疑那个包的安装部分终止了。重新安装程序包“Rcpp”为我解决了这个问题。

#4


0  

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.

这是因为您的GCC已经被更新了,而且它与您安装r时的版本有所不同,我也有同样的问题。

I removed the package "Rccp" by using:

我用“Rccp”来删除“Rccp”:

remove.packages("Rcpp")

Then you need to install it again. Just run:

然后你需要再次安装它。运行:

source("https://bioconductor.org/biocLite.R")
biocLite("Rcpp")

#1


16  

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

没有现成的包装很难说。我猜你小姐:

LinkingTo: Rcpp

in your DESCRIPTION file.

在你的描述文件。

#2


7  

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' ?

你是否有机会在RStudio中“创建一个软件包”?如果是的话,您是否意识到您可能错过了它的sibbling选项“创建一个w/ Rcpp包”?

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

有关详细信息,请参阅Rcpp与RStudio站点的使用页面,特别是关于包构建的最后一节。

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.

还要注意的是,我们已经写了一篇关于在您自己的包中使用Rcpp的文章,所以我建议您也看一下这篇文章。

#3


0  

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.

我遇到了同样的症状(Rcpp)。h:没有这样的文件或目录)当尝试在Ubuntu 14系统上安装“xml2”包时。在我的情况下,根本原因似乎是安装“Rcpp”的糟糕安装。有些文件在那里(Rcpp/libs),而另一些不在那里(Rcpp/include)。我不确定系统是如何进入这种状态的,但是我怀疑那个包的安装部分终止了。重新安装程序包“Rcpp”为我解决了这个问题。

#4


0  

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.

这是因为您的GCC已经被更新了,而且它与您安装r时的版本有所不同,我也有同样的问题。

I removed the package "Rccp" by using:

我用“Rccp”来删除“Rccp”:

remove.packages("Rcpp")

Then you need to install it again. Just run:

然后你需要再次安装它。运行:

source("https://bioconductor.org/biocLite.R")
biocLite("Rcpp")