#include <cstdio>
extern "C" void ADD(double *, double *, double *);
int main(int argc, char** argv)
{
double a=10;
double b=1;
double sum;
ADD(&a,&b,&sum);
printf("a + b = %lf\n", sum);
return 0;
}
subroutine add(a, b, sum)
real(8) a
real(8) b
real(8) sum
sum = a + b
end
5.98 KB, 下载次数: 21
测试例子
subroutine add(a, b, sum) Bind(C,Name="ADD")
real(8) a
real(8) b
real(8) sum
sum = a + b
end
fcode 发表于 2017-7-26 19:10
[mw_shl_code=fortran,true]subroutine add(a, b, sum) Bind(C,Name="ADD")
real(8) a
real(8) b
nm.png (38.06 KB, 下载次数: 428)
#include <cstdio>
extern "C" void add_(double *, double *, double *);
int main(int argc, char** argv)
{
double a=10;
double b=1;
double sum;
add_(&a,&b,&sum);
printf("a + b = %lf\n", sum);
return 0;
}
fcode 发表于 2017-7-27 11:13
不修改fortran的话,就修改C++的符号名,但是这可能因为不同编译器的符号修饰不同,而导致代码不通用。
请 ...
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |