【问题标题】:Link OpenBLAS to MinGW将 OpenBLAS 链接到 MinGW
【发布时间】:2020-01-04 08:52:28
【问题描述】:

我正在尝试在 Windows 上将 OpenBLAS 库与 MinGW w64 编译器链接。

这是我的代码:

#include <cstdio>
#include <cblas.h>
#include <cstdlib>

int main(){
    double  m[10],n[10];
    int i, result;

    for(i=0;i<10;i++)
        m[i] = 1.0l*rand()/RAND_MAX;
    for(i=0;i<10;i++)
        n[i] = 1.0l*rand()/RAND_MAX;
    result = cblas_ddot(10, m, 1, n, 1);
    return 0;
}

并使用此命令进行编译:

g++ ^ -IC:\OpenBLAS-0.3.6-x64\include -LC:\OpenBLAS-0.3.6-x64\lib -lopenblas blas.cpp

得到一个错误

undefined reference to `cblas_ddot'

我从 here 下载了预编译的二进制文件,并使用 64 位 Windows,g++ (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0

我该如何解决这个错误?

【问题讨论】:

    标签: windows mingw undefined-reference blas openblas


    【解决方案1】:

    一般建议是始终将源文件和目标文件放在链接库之前。

    一般来说,并不是所有的库函数都被使用,而是只使用主要代码源需要的那些。然后链接器需要在查看库之前知道未定义的符号。

    然后将blas.cpp 放在-lopenblas 之前应该可以工作。

    g++ ^ -IC:\OpenBLAS-0.3.6-x64\include -LC:\OpenBLAS-0.3.6-x64\lib blas.cpp -lopenblas
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多