【发布时间】:2021-03-17 22:21:43
【问题描述】:
我有 Fortran90 功能
function eg_fun(r) bind(c)
use, intrinsic :: iso_c_binding
implicit none
real(c_double), intent(in) :: r
real(c_double) :: eg_fun
real(c_double), parameter :: PI = acos(-1.d0)
eg_fun = PI * r * r + cos(r)
end function
还有我的 C 程序
#include <stdio.h>
#include <math.h>
extern double eg_fun(double *r);
int main(int argc, char **argv){
double r;
printf("Enter the argument\n");
scanf("%lf", &r);
printf("The result is %lf\n", eg_fun(&r));
return 0;
}
我想使用iso_c_binding工具在C程序下使用Fortran函数。但是,当我尝试使用 gcc -Wall main.c routine.f90 -o app -lgfortran 编译 thos 时,我收到了错误消息
/tmp/ccn2Zeac.o: In function `eg_fun':
routine.f90:(.text+0x42): undefined reference to `cos'
collect2: error: ld returned 1 exit status
我该如何解决这个问题?
【问题讨论】: