我正在尝试用Windows上的MinGW w64编译器来链接OpenBLAS库。
这是我的代码:
#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, Built by MinGW-W64 project) 8.1.0
如何修复此错误?
发布于 2019-09-02 15:35:39
一般的建议是始终将源文件和目标文件放在链接库之前。
一般来说,并不是所有的库函数都会被使用,而是只使用主代码源需要的那些函数。然后,在查看库之前,链接器需要知道未定义的符号。
那么把blas.cpp放在-lopenblas之前应该行得通。
g++ ^ -IC:\OpenBLAS-0.3.6-x64\include -LC:\OpenBLAS-0.3.6-x64\lib blas.cpp -lopenblashttps://stackoverflow.com/questions/57737949
复制相似问题