我在测试cblas ddot,我使用的代码来自link,我将其修复为
#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我检查了/usr/include/cblas.h中的cblas文件,注意到有
double cblas_ddot(const int N, const double *X, const int incX,
const double *Y, const int incY);我不知道哪里出了问题。为什么编译器说"cblas_ddot“是未定义的引用?
发布于 2013-10-22 10:07:27
你不能只包含头文件--这只能告诉编译器函数存在于某个地方。您需要告诉链接器链接cblas库。
假设你有一个libcblas.a文件,你可以用-lcblas告诉GCC。
GNU site的网站告诉您如何做到这一点:
发布于 2013-10-23 09:17:39
我的问题刚刚解决了。原因是我在输入链接路径时犯了错误。感谢Jonathon Reinhart的回答,他们在学习如何在linux中编程时真的很有帮助。
编译命令包括:
gcc -c test.c
gcc -L/usr/lib64 test.o -lgsl -lgslcblas -lm其中"/usr/lib64“是正确的链接路径。
https://stackoverflow.com/questions/19507841
复制相似问题