请教一下,在c中调用fortran的subroutine,但是编译c文件的时候不能通过

william0218 2008-10-06 11:33:02
fortran文件如下:
randomnum.f90
--------------------------------------------------------------------
subroutine randomnum(iseed,fn_val)

real fn_val, rm
integer ia, ic, ir, iseed, ix, iy, j, m
parameter (m=714025, ia=1366, ic=150889, rm=1./m)
common /rndm/ ir(97), ix, iy

if(iseed .lt. 0) then

ix = mod(ic-iseed, m)

do j=1,97
ix = mod(ia*ix+ic, m)
ir(j) = ix
end do

ix = mod(ia*ix+ic, m)
iy = ix

end if

j = 1 + (97*iy)/m

if(j.gt.97 .or. j.lt.1) stop

iy = ir(j)
ix = mod(ia*ix+ic, m)
ir(j) = ix

fn_val = iy*rm

end subroutine randomnum

--------------------------------------------------------------------
编译命令如下:
/opt/intel/fc/10.1.013//bin/ifort -o randomnum.o -c randomnum.f90

c文件如下:
ccf.c
--------------------------------------------------------------------
#include <stdio.h>

extern void randomnum_(int * a,float * b);

int main(){

float b;
int a=1;
int i = 0;

for(; i <10 ; i++){
randomnum_(&a,&b);
printf("b = %f\n",b);
}

}
--------------------------------------------------------------------
编译命令如下:
gcc -o ccf ccf.c randomnum.o

出错信息如下:
[william@localhost workspace]$ gcc -o ccf ccf.c randomnum.o
randomnum.o: In function `randomnum_':
randomnum.f90:(.text+0x10e): undefined reference to `for_stop_core'
collect2: ld returned 1 exit status
[william@localhost workspace]$
请问这是什么问题,应该如何解决,谢谢!

...全文
116 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
intel_iclifort 2008-10-10
  • 打赏
  • 举报
回复
[Quote=引用楼主 william0218 的帖子:]
出错信息如下:
[william@localhost workspace]$ gcc -o ccf ccf.c randomnum.o
randomnum.o: In function `randomnum_':
randomnum.f90:(.text+0x10e): undefined reference to `for_stop_core'
collect2: ld returned 1 exit status
[william@localhost workspace]$
请问这是什么问题,应该如何解决,谢谢!
[/Quote]

应该是没有链接上Intel Fortran的库

gcc -o ccf ccf.c randomnum.o -lifcore -L/opt/intel/fc/10.1.013/lib 试试 (这里假定你的Intel Fortran安装在 /opt/intel/fc/10.1.013/)

如果还有undefined reference, 就用 nm 继续去找

lann64 2008-10-06
  • 打赏
  • 举报
回复
从提示看,似乎fortran程序有问题。不懂fortran
lzp765 2008-10-06
  • 打赏
  • 举报
回复
不懂,来顶下。。。
william0218 2008-10-06
  • 打赏
  • 举报
回复
我觉得也有可能是在编译c时,缺少了什么库文件,但是,不知道到底缺了什么,非常简单的小程序阿,应该用不到什么特殊函数才是啊。

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧