【问题标题】:#include <Rcpp11> file not found error#include <Rcpp11> 文件未找到错误
【发布时间】:2014-07-18 14:27:43
【问题描述】:

我正在尝试使用 r 中的 Rcpp11 包,来自它的源代码:

devtools::install_github("Rcpp11/Rcpp11")

我在这里读到:http://blog.r-enthusiasts.com/2014/05/27/disambiguating-rcpp11-and-rcpp/

我可以在.cpp 文件的开头使用include &lt;Rcpp11&gt; + using namespace Rcpp11,但在采购时出现此错误:

 egfile.cpp:1:10: fatal error: 'Rcpp11' file not found
 #include <Rcpp11>
           ^
 1 error generated.

egfile.cpp:

#include <Rcpp11>
using namespace Rcpp11;

// Below is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp 
// function (or via the Source button on the editor toolbar)

// For more on using Rcpp click the Help button on the editor toolbar

// [[Rcpp::export]]
int timesTwo(int x) {
   return x * 2;
}

对此有什么帮助吗?还是我应该遵循// [[Rcpp::plugins(cpp11)]] 方法?

更新:使用attributes::sourceCpp()

devtools::install_github("Rcpp11/attributes")

然后从干净的会话重新启动:

library(Rcpp11)
attributes::sourceCpp("egfile.cpp") # in home directory.

我明白了:

In file included from file2c1e303c4ed6.cpp:1:
    In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
    In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
    /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_pnorm' in the global namespace
RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
#define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:14:31: note: expanded from macro 'RCPP_DPQ'
decltype(sapply( x, ::Rf_p##__NAME__, VAL, lower, log ))                                          \
                 ~~^
                     <scratch space>:208:1: note: expanded from here
                 Rf_pnorm
                 ^
                     In file included from file2c1e303c4ed6.cpp:1:
                     In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
                     In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
                     /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_pnorm' in the global namespace
                 RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
                 #define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:16:29: note: expanded from macro 'RCPP_DPQ'
                 return sapply( x, ::Rf_p##__NAME__, VAL, lower, log ) ;                                                      \
                                ~~^
                                    <scratch space>:208:1: note: expanded from here
                                Rf_pnorm
                                ^
                                    In file included from file2c1e303c4ed6.cpp:1:
                                    In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
                                    In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
                                    /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_qnorm' in the global namespace
                                RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
                                #define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:20:31: note: expanded from macro 'RCPP_DPQ'
                                decltype(sapply( x, ::Rf_q##__NAME__, VAL, lower, log ))                                          \
                                                 ~~^
                                                     <scratch space>:208:1: note: expanded from here
                                                 Rf_qnorm
                                                 ^
                                                     In file included from file2c1e303c4ed6.cpp:1:
                                                     In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp11:4:
                                                     In file included from /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp.h:238:
                                                     /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:54:1: error: no member named 'Rf_qnorm' in the global namespace
                                                 RCPP_DPQ__2(norm,double mean = 0, double sd = 1, mean, sd )
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                     /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:30:51: note: expanded from macro 'RCPP_DPQ__2'
                                                 #define RCPP_DPQ__2(__NAME__,PAR1,PAR2,VAL1,VAL2) RCPP_DPQ(__NAME__,RCPP_ECHO(RCPP_CONCAT(PAR1,PAR2)), RCPP_ECHO(RCPP_CONCAT(VAL1,VAL2)) )
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                     /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp11/include/Rcpp/stats/stats.h:22:29: note: expanded from macro 'RCPP_DPQ'
                                                 return sapply( x, ::Rf_q##__NAME__, VAL, lower, log ) ;                                                      \
                                                                ~~^
                                                                    <scratch space>:208:1: note: expanded from here
                                                                Rf_qnorm
                                                                ^
                                                                    4 errors generated.
                                                                make: *** [file2c1e303c4ed6.o] Error 1
                                                                Error in dyn.load(basename(dynlib)) : 
                                                                    unable to load shared object '/private/var/folders/77/9nq5hj5d37b1rhbzdt0z3twr0000gn/T/RtmpcjWOsg/file2c1e303c4ed6.so':
                                                                    dlopen(/private/var/folders/77/9nq5hj5d37b1rhbzdt0z3twr0000gn/T/RtmpcjWOsg/file2c1e303c4ed6.so, 6): image not found
                                                                In addition: Warning message:
                                                                    running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB 'file2c1e303c4ed6.cpp'' had status 1 

【问题讨论】:

  • 我已将标签从 rcpp 更改为 rcpp11。
  • 而且没有plugin=Rcpp11这样的东西

标签: r rstudio rcpp11


【解决方案1】:

您可能正在尝试从 R Studio 编译它,它将使用 Rcpp::sourceCpp。您需要实现 attributes 包中的 sourceCpp 来生成 Rcpp11 的胶水代码。 attributes 可从 github 获得:

devtools::install_github("Rcpp11/attributes")

然后使用这个版本编译你的文件,即

attributes::sourceCpp( "yourfile.cpp" )

使用 Rstudio ui 编译 Rcpp11 文件是我们尚未处理的事情,但我们认为需要 here

【讨论】:

  • 很好的猜测——抱歉我的问题含糊不清。我已相应地对其进行了修改。请参阅更新,因为这样做会导致编译错误。感谢您的早期支持,对新的仅标头包感到非常兴奋。
  • 你提到的新错误我相信昨天在版本 370 和 371 之间已修复。请参阅travis-ci.org/Rcpp11/Rcpp11/builds 两者之间有一些错误,但当前的快照版本。
  • 也欢迎 @user3686430 在 Stack Overflow 上。如果您使用您的个人资料(例如,而不是一些随机的用户名)来表明自己的身份,您将获得更好的答案。如果我的回答适合你,请考虑接受(左上角旁边的勾号)。
  • 我遇到了与原始海报相同的问题。试过这个解决方案。但是,函数 attributes::sourceCpp() 失败并出现错误。这些 cmets 是 2014 年的,如果这个答案仍然有效,你能给我提个醒吗?谢谢!
猜你喜欢
  • 1970-01-01
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-29
  • 1970-01-01
  • 2015-03-25
  • 2016-06-05
相关资源
最近更新 更多