0

I am trying to use spsolve function in RcppArmadillo. According to this post, I compiled the following test.cpp code (same with the example of that post).

// Important: this definition ensures Armadillo enables SuperLU
#define ARMA_USE_SUPERLU 1

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]

using namespace arma;

// [[Rcpp::export]]
void superLuDemo() {
  sp_mat A = sprandu<sp_mat>(1000, 1000, 0.1);
  
  vec b = randu<vec>(1000);
  mat B = randu<mat>(1000, 5);
  
  vec x = spsolve(A, b);  // solve one system
  mat X = spsolve(A, B);  // solve several systems
  
  bool status = spsolve(x, A, b);  // use default solver
  if (status == false)  { Rcpp::Rcout << "no solution" << endl; }
  
  spsolve(x, A, b, "lapack");   // use LAPACK  solver
  spsolve(x, A, b, "superlu");  // use SuperLU solver
  
  Rcpp::Rcout << "Done.\n";
}

But I get compile error.

"C:/rtools40/mingw64/bin/"g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-41~1.0/include" -DNDEBUG -I../inst/include -fopenmp  -I"C:/Users/mirai/Documents/R/win-library/4.1/Rcpp/include" -I"C:/Users/mirai/Documents/R/win-library/4.1/RcppArmadillo/include" -I"C:/Users/mirai/Dropbox/Rfiles/Pinterest_research/empirical_analysis3"        -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -c test.cpp -o test.o
C:/rtools40/mingw64/bin/g++ -shared -s -static-libgcc -o sourceCpp_4.dll tmp.def test.o -fopenmp -LC:/PROGRA~1/R/R-41~1.0/bin/x64 -lRlapack -LC:/PROGRA~1/R/R-41~1.0/bin/x64 -lRblas -lgfortran -lm -lquadmath -lsuperlu -LC:/PROGRA~1/R/R-41~1.0/bin/x64 -lR
C:/rtools40/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsuperlu
collect2.exe: error: ld returned 1 exit status
Error in Rcpp::sourceCpp("empirical_analysis3/test.cpp") : 
  Error occurred building shared library.

Do you have any ideas? Many thanks.


Environment

  • OS: Windows10
  • R: ver4.1.0
  • RcppArmadillo: ver0.10.5.0.0
  • Did you install the superLU library? Note the part of the post that says "However, this requires access to the SuperLU library". It looks like with windows you'll have to compile that yourself – MrFlick Jul 01 '21 at 07:06
  • Thank you, but I am not familiar with c language. Could you provide some tutorial pages for how to install library and necessary steps after installing? – mirai igarashi Jul 01 '21 at 07:25

0 Answers0