在开发使用Rcpp和unit testing with Catch via the testthat package的R包BayesMallows时.最近,我们注意到一个问题,它在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 <your@email.com>
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
如果此时i运行Rcpp::compileAttributes()
,则在src/RcppExports.cpp
中生成以下条目:
RcppExport SEXP run_testthat_tests(void *);
这一行在CRAN上导致了一个问题,特别是"LTO构建失败:类型违反了C++One定义规则".我们目前已手动修复了该问题,方法是将该行修改为以前的状态,即
RcppExport SEXP run_testthat_tests(SEXP);
然而,每当我重新运行Rcpp::compileAttributes()
时,这个SEXP
参数被更改为void *
.我使用的是R4.3.1,我在Mac和Windows上都经历过这种情况.我运行了测试版本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
对于发生了什么,以及如何修复它,有什么建议吗?