Rcpp 编译属性创建 void 参数

问题描述 投票:0回答:1

在开发 R 包 BayesMallows 时,它使用 Rcpp 以及 通过 testthat 包使用 Catch 进行单元测试。最近我们注意到一个在 CRAN 上造成 LTO 问题的问题。这是一个最小的例子。

首先我创建一个 Rcpp 包。

Rcpp::Rcpp.package.skeleton()
setwd("anRpackage/")

然后使用 Catch 添加单元测试:

testthat::use_catch()

然后将说明修改为以下内容:

Package: anRpackage
Type: Package
Title: What the Package Does in One 'Title Case' Line
Version: 1.0
Date: 2023-08-29
Author: Your Name
Maintainer: Your Name <[email protected]>
Description: One paragraph description of what the package does as one or more full sentences.
License: GPL (>= 2)
Imports: Rcpp (>= 1.0.11)
LinkingTo: Rcpp, testthat
Suggests: xml2

如果我此时运行

Rcpp::compileAttributes()
,则会在
src/RcppExports.cpp
中生成以下条目:

RcppExport SEXP run_testthat_tests(void *);

这一行会导致 CRAN 出现问题,特别是“LTO 构建失败:类型违反了 C++ 单一定义规则”。我们现在已手动修复了该问题,方法是将该行修改为之前的内容,即

RcppExport SEXP run_testthat_tests(SEXP);

但是,每当我重新运行

Rcpp::compileAttributes()
时,这个
SEXP
参数就会更改为
void *
。我使用的是 R4.3.1,在 Mac 和 Windows 上都遇到过这种情况。我运行 testthat 版本 3.1.10 和 Rcpp 版本 1.0.11。

在 Mac 上,命令

gcc --version
返回以下内容:

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix

对发生的情况以及如何解决有什么建议吗?

c++ r rcpp cran
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.