请问如何在Fortran里面调用C函数??

ctech 2012-07-27 10:35:09
这是 .c 文件
——————————————————————————————————
#include <stdio.h>
#include <sys/sysinfo.h>
#include <stdlib.h>

void show ()
{
struct sysinfo info;
unsigned long ram_total = 0, ram_used = 0, swap_total = 0, swap_used = 0;
int mem_unit;

sysinfo(&info);

mem_unit = info->mem_unit;

ram_total = info.totalram * mem_unit / 1024000;
ram_used = ram_total - info.freeram * mem_unit / 1024000;
swap_total = info.totalswap * mem_unit / 1024000;
swap_used = swap_total - info.freeswap * mem_unit / 1024000;

printf("系统共有内存%ldMb, 已用%ldMb, 共有交换分区%ldMb, 已用%ldMb\n",
ram_total, ram_used, swap_total, swap_used);

return;
}
——————————————————————————————————————————


这是.f90文件

program main

call show()

end program main


请问如何做才能在fotran文件里调用上面.c文件里的show()函数呢???谢谢!
...全文
466 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pathuang68 2012-07-28
  • 打赏
  • 举报
回复
下面几篇文章都相当不错:
1. Using C/C++ and Fortran together

2. C/C++调用Fortran的使用说明
xunxun 2012-07-28
  • 打赏
  • 举报
回复
首先需要确定使用的什么Fortran编译器以及它采用的name mangle形式

如果支持Fortran2003标准,那么可以使用ISO_C_BINDING实现C的改编接口(不论大写/小写/下划线)
Gloveing 2012-07-28
  • 打赏
  • 举报
回复
把C写的函数做成一个DLL
ctech 2012-07-28
  • 打赏
  • 举报
回复
Anybody help

69,371

社区成员

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

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