我正在尝试链接OpenBLAS图书馆 MinGW w64 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;
}
并使用此命令进行编译:
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,由 MinGW-W64 项目构建)8.1.0
如何修复此错误?
最佳答案
一般建议是始终将源文件和目标文件放在链接库之前。
一般来说,并不是使用所有库函数,而是仅使用主代码源所需的库函数。然后链接器在查看库之前需要知道 undefined symbol 。
然后将 blas.cpp
放在 -lopenblas
之前应该可以工作。
g++ ^ -IC:\OpenBLAS-0.3.6-x64\include -LC:\OpenBLAS-0.3.6-x64\lib blas.cpp -lopenblas
关于windows - 将 OpenBLAS 链接到 MinGW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57737949/