首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >#包括未找到的<Rcpp11>文件

#包括未找到的<Rcpp11>文件
EN

Stack Overflow用户
提问于 2014-05-29 06:43:19
回答 1查看 830关注 0票数 6

我试图使用r中的Rcpp11包,它的源代码位于:

代码语言:javascript
复制
devtools::install_github("Rcpp11/Rcpp11")

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

我可以在我的include <Rcpp11>文件的开头使用.cpp + using namespace Rcpp11,但是我在源代码中得到了这个错误:

代码语言:javascript
复制
 egfile.cpp:1:10: fatal error: 'Rcpp11' file not found
 #include <Rcpp11>
           ^
 1 error generated.

其中egfile.cpp

代码语言:javascript
复制
#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()

代码语言:javascript
复制
devtools::install_github("Rcpp11/attributes")

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

代码语言:javascript
复制
library(Rcpp11)
attributes::sourceCpp("egfile.cpp") # in home directory.

我得到:

代码语言:javascript
复制
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 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-29 07:18:16

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

代码语言:javascript
复制
devtools::install_github("Rcpp11/attributes")

然后使用此版本编译您的文件,即

代码语言:javascript
复制
attributes::sourceCpp( "yourfile.cpp" )

使用Rstudio编译Rcpp11文件是我们尚未处理的问题,但我们认为需要使用这里

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23927305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档