我想用fortran调用C函数(需要这个用于项目)。因此首先尝试通过fortran简单地调用一个非参数化的无效函数。从Fortran调用C函数
请帮助我解决给定代码中的以下错误。
C代码的矩阵乘法:
#include <stdio.h>
extern "C"
{ void __stdcall mat();
}
void mat()
{
int m, n, p, q, c, d, k, sum = 0;
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
int first[m][n];
printf("Enter the elements of first matrix\n");
for ( c = 0 ; c < m ; c++)
for (d = 0 ; d < n ; d++)
scanf("%d", &first[c][d]);
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
int second[p][q];
if (n != p)
printf("Matrices with entered orders can't be multiplied with each other.\n");
else
{
printf("Enter the elements of second matrix\n");
for (c = 0 ; c < p ; c++)
for (d = 0 ; d < q ; d++)
scanf("%d", &second[c][d]);
int multiply[m][q];
for (c = 0 ; c < m ; c++)
{
for (d = 0 ; d < q ; d++)
{
for (k = 0 ; k < p ; k++)
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of entered matrices:-\n");
for (c = 0 ; c < m ; c++)
{
for (d = 0 ; d < q ; d++)
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
}
int main()
{
mat();
return 0;
}
而且,从调用FORTRAN函数垫,我写的代码是:
program mat_mult !This is a main program.
call mat()
stop
end
上执行的C文件我得到以下错误:
matrix_mult.c:5:错误:期望的标识符或'('在字符串常量之前
在使用F77编译器执行Fortran文件,我得到以下错误:
/tmp/ccQAveKc.o:在功能MAIN__': matrix_mult.f:(.text+0x19): undefined reference to
mat_” collect2:LD返回1个退出状态
请帮助我确定错误/正确的代码。 谢谢。