I am trying to figure out an error that stopped me from making an R package "whyNotWork" using RcppArmadillo. The package contains only one .cpp file with one simple function which returns the eigen values of a matrix:
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
// [[Rcpp::export]]
arma::vec getEigenValues(arma::mat M)
{
return arma::eig_sym(M);
}
In the DESCRIPTION file I added:
Imports:
Rcpp (>= 0.12.1), RcppArmadillo
LinkingTo:
Rcpp, RcppArmadillo
Depends: RcppArmadillo
In the NAMESPACE file I added:
exportPattern("^[[:alpha:]]+")
useDynLib(whyNotWork)
import(RcppArmadillo)
importFrom(Rcpp, evalCpp)
That function works fine if I was not trying to make a package--the "source" button will successfully load the function and it works correctly. However, when making the package, hitting the "Build & Reload" button will give the following error:
arma.o:arma.cpp(.text$_ZN4arma6auxlib7eig_symIdNS_3MatIdEEEEbRNS_3ColIT_EERKNS_4BaseIS5_T0_EE[_ZN4arma6auxlib7eig_symIdNS_3MatIdEEEEbRNS_3ColIT_EERKNS_4BaseIS5_T0_EE]+0x28d): undefined reference to `dsyev_'
I googled "dsyev" and it seems to be related to LAPCAK..
A solution:
New a .txt file in the src folder. Add
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
in the file.
Rename the txt file as Makevars.win (if it's not Windows system, no .win). Package is successfully made.
The solution is found by comparing the files generated from RcppArmadillo.package.skeleton() and those from Rstudio