使用 cblas 库时出现“对‘cblas_ddot’的未定义引用”

2024-04-04

我正在测试 cblas ddot,我使用的代码来自link https://stackoverflow.com/questions/14470799/calling-ddot-function-in-blas-library我将其修复为

#include <stdio.h>
#include <stdlib.h>
#include <cblas.h>

int main()
{
    double  m[10],n[10];
    int i;
    int result;

    printf("Enter the elements into first vector.\n");
    for(i=0;i<10;i++)
        scanf("%lf",&m[i]);

    printf("Enter the elements into second vector.\n");
    for(i=0;i<10;i++)
        scanf("%lf",&n[i]);

    result = cblas_ddot(10, m, 1, n, 1);
    printf("The result is %d\n",result);

    return 0;
}

然后我编译的时候,结果是:

/tmp/ccJIpqKH.o: In function `main':
test.c:(.text+0xbc): undefined reference to `cblas_ddot'
collect2: ld returned 1 exit status

我检查了 cblas 文件/usr/include/cblas.h,并注意到有

double cblas_ddot(const int N, const double *X, const int incX,
              const double *Y, const int incY);

我不知道哪里出了问题。为什么编译器说“cblas_ddot”是未定义的引用?


您不能只包含标头 - 这只告诉编译器这些函数存在某处。您需要告诉链接器链接 cblas 库。

假设你有一个libcblas.a文件,你可以告诉 GCC 相关信息-lcblas.

GNU 科学图书馆的网站告诉您如何做到这一点:

  • 2.2 编译和链接 http://www.gnu.org/software/gsl/manual/html_node/Compiling-and-Linking.html#Compiling-and-Linking
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 cblas 库时出现“对‘cblas_ddot’的未定义引用” 的相关文章

随机推荐