rcpp - 使用 Rcpp 和 C++20 的 R 包

标签 rcpp r-package

我使用 Rcpp 制作了一个简单的 R 包,但是当我设置时 系统要求:C++20 关于描述,我在构建时遇到以下错误。

clang++ -arch x86_64 -std=gnu++20 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include' -I/opt/R/x86_64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -UNDEBUG -Wall -pedantic -g -O0 -c RcppExports.cpp -o RcppExports.o
   In file included from RcppExports.cpp:4:
   In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/Rcpp.h:78:
   In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/Rcpp/sugar/sugar.h:31:
   In file included from /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/Rcpp/sugar/functions/functions.h:42:
   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/Rcpp/sugar/functions/sapply.h:36:19: error: no template named 'result_of' in namespace 'std'; did you mean 'traits::result_of'?
           typedef typename ::std::result_of<Function(typename SugarExpression::stored_type)>::type type;
                            ^~~~~~~~~~~~~~~~
                            traits::result_of
   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library/Rcpp/include/Rcpp/traits/result_of.h:30:8: note: 'traits::result_of' declared here
   struct result_of{
          ^
   1 error generated.
   make: *** [RcppExports.o] Error 1
   ERROR: compilation failed for package

是否可以使用 C++20 构建包?

最佳答案

最后一次 Rcpp 版本(版本 1.0.10)发生在 1 月份。但是使用 clang++ 支持 C++20 所需的代码是在二月份添加的,参见https://github.com/RcppCore/Rcpp/pull/1248 。您可以从项目 drat 存储库获取中间版本:

install.packages("Rcpp", repos="https://RcppCore.github.io/drat")

未经测试,因为您没有提供最小的示例。

关于rcpp - 使用 Rcpp 和 C++20 的 R 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76454448/

相关文章:

R CRAN,R3.2升级后安装库Rcpp失败

r - 除了使用 R 基函数之外,是否有一种有效的方法可以获得 "pmax"?

c++ - C/C++ 数组指针对象的 Rcpp 返回

r - 安装 R 包时出错

c++ - 使用外部 C 库在 Rcpp 中编译 C++

c++ - 如何在 Rcpp 中构建常量矩阵?

c++ - 已安装 Rcpp Rtools 但未找到错误消息 g++

r - 无法在 Linux Mint 19.3 中安装 R 3.6.2 中的 httr 包

r - 如何查看软件包许可文件?

r - 使用 R 的 C API 更改向量的大小