"Error in sourceCpp("xx.cpp" 的错误:构建共享库时发生错误 1。”

Error of "Error in sourceCpp("xx.cpp") : Error 1 occurred building shared library."

我想根据一篇论文做一些研究,论文的代码是:https://github.com/Xiaolu-Zhu/LongitudinalClustering

在“sample.R”脚本中,有这么一条命令

sourceCpp("admmmcp_code.cpp");

然后就报错了

Error in sourceCpp("admmmcp_code.cpp") : 
Error 1 occurred building shared library.

我已经使用

检查了 Rtools
writeLines('PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"', con = "~/.Renviron")

Sys.which("make")

所以我相信我已经在 Windows 上正确安装了 Rtools。

既然我们已经确定您有一个有效的 Rtools 设置,请确保您有需要 个 R 包。我知道,而且它在这里有效:

R> download.file("https://raw.githubusercontent.com/Xiaolu-Zhu/LongitudinalClustering/master/admmmcp_code.cpp", "/tmp/admmmcp_code.cpp")
trying URL 'https://raw.githubusercontent.com/Xiaolu-Zhu/LongitudinalClustering/master/admmmcp_code.cpp'
Content type 'text/plain; charset=utf-8' length 8118 bytes
==================================================
downloaded 8118 bytes

R> Rcpp::sourceCpp("/tmp/admmmcp_code.cpp")
R> ls()
 [1] "prclust_admm"     "prox_L2"         
 [3] "residual_dual"    "residual_primal" 
 [5] "tolerance_dual"   "tolerance_primal"
 [7] "update_B"         "update_B_ini"    
 [9] "update_Lambda"    "update_V"        
R> 

因此,请特别确保您已安装 RcppArmadillo