Search code examples
rrcpp

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


I'd like to do some research based on a paper whose codes are: https://github.com/Xiaolu-Zhu/LongitudinalClustering.

In the "sample.R" script, there is such a command

sourceCpp("admmmcp_code.cpp");

And it goes wrong with the error

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

I have checked about the Rtools with

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

and

Sys.which("make")

So I believe I have installed the Rtools correctly on my Windows.


Solution

  • Now that we have established that you have a working Rtools setup, make sure you have required R packages. I do, and it works here:

    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> 
    

    So in particular, make sure you have RcppArmadillo installed.