RcppArmadillo”一词;inDL(x,as.logical(local),as.logical(now),…)中出错”;Windows平台下

RcppArmadillo”一词;inDL(x,as.logical(local),as.logical(now),…)中出错”;Windows平台下,r,rcpp,armadillo,R,Rcpp,Armadillo,我用Rcpp和RcppArmadillo编写了一些函数,如下所示 示例.cpp: #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] #include <iostream> #include <math.h> using namespace Rcpp; // using namespace RcppArmadillo; using namespace arma; using nam

我用Rcpp和RcppArmadillo编写了一些函数,如下所示


示例.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;
}
我发现关键问题在于矩阵乘法。因为我试图删除第二个函数
multiply2
。然后剩下的代码可以在Windows下成功编译

例2.cpp


#包括
//[[Rcpp::depends(RcppArmadillo)]]
#包括
#包括
使用名称空间Rcpp;
//使用名称空间RcppArmadillo;
使用arma;
使用名称空间std;
//[[Rcpp::导出]]
双内1(数值向量x,数值向量y){
int K=x.长度();
双ip=0;
for(int k=0;k

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


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

在与编译器斗争了很长时间后,我发现关键点是
BLAS
库没有在我的Windows系统环境路径中正确设置

简言之,解决办法是:

  • 在下载预编译的OpenBLS二进制软件包(不要尝试在windows下编译最新版本,我在这方面浪费了很多时间)
  • Exactor
    OpenBLAS-v0.2.19-Win64-int32.zip
    到一些类似的
    C:\LIBS\OpenBLAS-v0.2.15-Win64-int32
  • C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin添加到
    路径中
  • [可选]创建名为
    BLAS_LIBS
    的新环境变量,其值为
    C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin
  • 重新启动RStudio,问题就解决了
  • 我通过安装
    RcppArmadillo
    从源代码处通过安装.packages(“RcppArmadillo”,type=“source”)
    找到这个解决方案,这次RStudio在编译过程中抛出相同的错误,因此安装失败


    但是,如果我只使用
    install.packages(“RcppArmadillo”)
    ,RStudio将安装
    RcppArmadillo
    的二进制版本,因此在与编译器斗争了很长时间后,我没有收到任何关于缺少
    BLAS

    的反馈,我发现关键点是在我的windows系统环境路径中未正确设置
    BLAS

    简言之,解决办法是:

  • 在下载预编译的OpenBLS二进制软件包(不要尝试在windows下编译最新版本,我在这方面浪费了很多时间)
  • Exactor
    OpenBLAS-v0.2.19-Win64-int32.zip
    到一些类似的
    C:\LIBS\OpenBLAS-v0.2.15-Win64-int32
  • C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin添加到
    路径中
  • [可选]创建名为
    BLAS_LIBS
    的新环境变量,其值为
    C:\LIBS\OpenBLAS-v0.2.15-Win64-int32\bin
  • 重新启动RStudio,问题就解决了
  • 我通过安装
    RcppArmadillo
    从源代码处通过安装.packages(“RcppArmadillo”,type=“source”)
    找到这个解决方案,这次RStudio在编译过程中抛出相同的错误,因此安装失败


    但是,如果我只使用
    install.packages(“RcppArmadillo”)
    ,RStudio将安装二进制版本的
    RcppArmadillo
    ,因此,我没有收到任何关于缺少
    BLAS

    的反馈,我认为一种更简单的方法早在R随附的R安装和管理手册中就有描述。我认为一种更简单的方法早在R随附的R安装和管理手册中就有描述。
    > 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.
    
    #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) ;
    }