我正在尝试编写一个C封装器,以调用Fortran模块中的一组函数。我从基本的东西开始,但是我缺少重要的东西。
我尝试添加/预置不同数量的下划线。我还尝试使用gcc而不是gfortran进行链接。下面显示的内容给出了最简单的错误。
我正在使用运行Yosemite 10.10.3的Mac,GNU Fortran 5.1.0和Xcode附带的C编译器。
main.c
我尝试添加/预置不同数量的下划线。我还尝试使用gcc而不是gfortran进行链接。下面显示的内容给出了最简单的错误。
我正在使用运行Yosemite 10.10.3的Mac,GNU Fortran 5.1.0和Xcode附带的C编译器。
main.c
#include "stdio.h"
int main(void)
{
int a;
float b;
char c[30];
extern int _change_integer(int *a);
printf("Please input an integer: ");
scanf("%d", &a);
printf("You new integer is: %d\n", _change_integer(&a));
return 0;
}
intrealstring.f90
module intrealstring
use iso_c_binding
implicit none
contains
integer function change_integer(n)
implicit none
integer, intent(in) :: n
integer, parameter :: power = 2
change_integer = n ** power
end function change_integer
end module intrealstring
以下是我的编译方式和错误信息:
$ gcc -c main.c
$ gfortran -c intrealstring.f90
$ gfortran main.o intrealstring.o -o cwrapper
Undefined symbols for architecture x86_64:
"__change_integer", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
$