我正在尝试用 C 语言编译一个程序,该程序使用线性代数的 BLAS 接口(interface)。该系统在 /usr/lib64/libblas.*
中具有 BLAS 库(.a
和 .so
文件)但没有 cblas.h
在/usr/include
.我尝试在本地复制 header 并编译以下简单程序:
#include <stdio.h>
#include <cblas.h>
int main() {
double foo[] = {1.1,1.2,1.3};
printf("Vector norm: %g\n",cblas_dnrm2 ( 3, foo, 1 ));
}
有选项
gcc blas_test.c -L/usr/lib64 -lblas -I.
但得到错误undefined reference to 'cblas_dnrm2'
如何正确链接提供的库?
更新:如果我尝试链接到 libcblas.so.3
或 libcblas.so.3.0
在/usr/lib64/atlas
像这样:
gcc blas_test.c -L/usr/lib64/atlas -lcblas -I.
我收到错误 /usr/bin/ld: cannot find -lcblas
.同样,它可以很好地找到头文件,但找不到共享库对象。
gcc 似乎寻找 .a
和 .so
文件,而不是 .so.3
文件。解决方法如下:
gcc blas_test.c -L /usr/lib64/atlas -l :libcblas.so.3 -I.
我是一名优秀的程序员,十分优秀!