首页 > 解决方案 > 将 OpenBLAS 链接到 MinGW

问题描述

我正在尝试将OpenBLAS库与Windows 上的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'

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

我该如何解决这个错误?

标签: windowsmingwundefined-referenceblasopenblas

解决方案


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

通常,并非所有库函数都被使用,而仅使用主要代码源所需的函数。然后链接器需要在查看库之前知道未定义的符号。

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

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

推荐阅读