将 OpenBLAS 链接到 MinGW [英] Link OpenBLAS to MinGW

查看:76
本文介绍了将 OpenBLAS 链接到 MinGW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 OpenBLAS 库与 Windows 上的 MinGW w64 编译器.

I'm trying to link OpenBLAS library with MinGW w64 compiler on Windows.

这是我的代码:

#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;
}

并使用此命令进行编译:

and compiling with this command:

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,由 MinGW-W64 项目构建)8.1.0

I downloaded precompiled binaries from here and using 64bit Windows, g++ (x86_64-win32-seh-rev0, Built by MinGW-W64 project) 8.1.0

我该如何解决这个错误?

How can I fix this error?

推荐答案

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

A general suggestion is to always put source and object files before linked libraries.

通常不会使用所有的库函数,而只会使用主要代码源所需的函数.然后链接器需要在查看库之前知道未定义的符号.

In general not all of the library functions are used, but only the ones needed by the main source of code. Then the linker needs to know the undefined symbols before looking into the libraries.

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

Then putting blas.cpp before -lopenblas should work.

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

这篇关于将 OpenBLAS 链接到 MinGW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆