【问题标题】:RcppArmadillo "Error in inDL(x, as.logical(local), as.logical(now), ...)" under Windows Platform [closed]Windows平台下的RcppArmadillo“inDL(x,as.logical(local),as.logical(now),...)中的错误”[关闭]
【发布时间】:2018-10-11 12:35:12
【问题描述】:

我有一些像这样用 Rcpp 和 RcppArmadillo 编写的函数


example.cpp:

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


using namespace Rcpp;
// using namespace RcppArmadillo;
using namespace arma;
using namespace std;


// [[Rcpp::export]]
double inner1(NumericVector x, NumericVector y) {
  int K = x.length() ;
  double ip = 0 ;
  for (int k = 0 ; k < K ; k++) {
    ip += x(k) * y(k) ;
  }
  return(ip) ;
}



// [[Rcpp::export]]
mat multiply2(mat A, mat B) {
  return A * B;
}

然后我使用Rcpp::sourceCpp('example.cpp'),它在 Ubuntu 下运行良好。

(我之前跑过library(Rcpp)library(RcppArmadillo)

但是,当我迁移到 Windows 平台时,RStudio 的 Throw 报错说:

> Rcpp::sourceCpp('R:/example.cpp')
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/[Username]/AppData/Local/Temp/RtmpG6H80X/sourceCpp-x86_64-w64-mingw32-0.12.19/sourcecpp_40b04b2c2bcf/sourceCpp_4.dll':
  LoadLibrary failure: The specified procedure could not be found.

我发现关键问题在于矩阵乘法。由于我尝试删除第二个函数multiply2。那么剩下的代码就可以在windows下编译成功了。

example2.cpp


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


using namespace Rcpp;
// using namespace RcppArmadillo;
using namespace arma;
using namespace std;


// [[Rcpp::export]]
double inner1(NumericVector x, NumericVector y) {
  int K = x.length() ;
  double ip = 0 ;
  for (int k = 0 ; k < K ; k++) {
    ip += x(k) * y(k) ;
  }
  return(ip) ;
}

我尝试了其他一些代码,发现在代码中使用矩阵乘法*时会出现此错误。

那么,为什么 RcppArmadillo 中的矩阵乘法在 Windows 平台下会失败?

【问题讨论】:

    标签: r rcpp armadillo


    【解决方案1】:

    折腾了半天编译器,发现关键是我的windows系统环境路径下BLAS库没有正确设置。

    简而言之,解决方案是:

    1. Here下载OpenBLS的预编译二进制包(不要尝试在windows下编译最新版本,我浪费了很多时间)
    2. Exactor OpenBLAS-v0.2.19-Win64-int32.zipC:\LIBS\OpenBLAS-v0.2.15-Win64-int32 这样的地方
    3. C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin 添加到您的PATH
    4. [可选] 创建一个名为BLAS_LIBS的新环境变量,其值为C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin
    5. 重启RStudio,问题解决。

    我通过install.packages("RcppArmadillo", type = "source")从源代码安装RcppArmadillo找到了这个解决方案,这次RStudio在编译过程中抛出了同样的错误,所以安装失败。

    但是,如果我只使用install.packages("RcppArmadillo"),RStudio 将安装RcppArmadillo 的二进制版本,所以我没有收到任何关于缺少BLAS 的反馈。

    【讨论】:

    • 我认为 R 附带的 R 安装和管理 手册中早就描述了一种更简单的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多