问题
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