Link OpenBLAS to MinGW

不打扰是莪最后的温柔 提交于 2021-01-28 07:09:27

问题


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

This is my code:

#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

and get an error

undefined reference to `cblas_ddot'

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?


回答1:


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.

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


来源:https://stackoverflow.com/questions/57737949/link-openblas-to-mingw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!