问题
I am calling a BLAS function in my code by including the BLAS library, and my code apparently is faulty somehow, as the compiler spits out the error: "ddot was not declared in this scope."
#include <stdio.h>
#include <stdlib.h>
#include <blas.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 = ddot(m,n);
printf("The result is %d\n",result);
return 0;
}
Any ideas on how I can fix this code properly?
回答1:
When calling from C, the function name must either be cblas_ddot()
(C calling conventions) or ddot_
(fortran calling conventions; note the trailing underscore.)
You are missing some function arguments. Try
result = cblas_ddot(10, m, 1, n, 1);
or equivalently
int len = 10, incm = 1, incn = 1;
// ...
result = ddot_(&len, m, &incm, n, &incn);
Also, ddot returns a double but you are assigning the result to an int.
来源:https://stackoverflow.com/questions/14470799/calling-ddot-function-in-blas-library