文件名 fortran_lib.f90。文件名可以自己定,子程序名可以自己定,注意 bind 指定的C调用名称。 // C++ 代码示例(main.cpp) #include <iostream> extern "C" { // 声明 Fortran 函数 void fadd_(int* arg1, double* arg2); } int main() { int a = 5; double b = 3.14; // 调用 Fortran 函数 ...
编译环境:Fortran:推荐使用Compaq Visual Fortran 6.0以上的版本,C++:Microsoft Visual C++6.0。 1. 显式链接, (a) 找开CVF编译器,然后新建一个Fortran DLL工程(选择Fortran Dynamic Link Library),并指定工程名,如下图所示: 按确定按钮,然后新建一个Fortran 源文件,并输入以下的Fortran代码: (这里仅为说明问题,...
1、首先,创建一个Fortran模块文件,例如module_example.f90,其中包含要调用的函数: module module_example implicit none integer, parameter :: dp = kind(1.0d0) contains subroutine example_subroutine(a, b, c) implicit none real(dp), intent(in) :: a, b real(dp), intent(out) :: c c = a +...
2, Fortran 调用 C 函数 编辑C源码add.c 1 #include 2 3 void add_(float *a, float *b, float *c) 4 { 5 *c = *a + *b; 6 printf(“%f + %f = %f\n“, *a, *b, *c); 7 } Notes The funtion name “add_“ 编译源代码 # gcc -o add.o -c add.c 编辑fortran 主程序main...
在C++工程文件中进行调用 intmain(){//第一步,加载fortran下生成的dll文件HINSTANCE hLibrary = LoadLibrary(TEXT("TESTFOR.dll"));//判断是否加载成功if(hLibrary ==NULL) {cout<<"Cannot open lib"<<endl; system("pause");return-1; }//第二步,从加载的结果 hLibrary 中查找函数并命名SUMMATOR summa...
。请问如何修改,就是Fortran子程序是个加法,然后C语言调用,子程序用Fortran主程序调用没有任何问题。
迦非喵:ubuntu+gfortran+C主程序调用Fortran子程序简单测试1 赞同 · 0 评论文章 这里继续重构: main.c #include<stdio.h>externdoubleadd(int*,double[],int*,double[]);doublear1[4]={1.0,2.0,3.0,4.0};doublear2[4]={5.0,6.0,7.0,8.0};intmain(intargc,char*argv[]){intx,y;doublez;x=3;y=3...
ADD = B(A) + D(C) RETURN END 编译主程序和 Fortran 添加函数源文件,如下所示: xlc -c example.c xlf -c add.f 从编译步骤链接对象文件以创建可执行文件add: xlc -o add example.o add.o 执行二进制: ./add 输出如下所示: The sum of 3 and 7 is 10...
1.Fortran 生成DLL 新建Fortran DLL程序test1.f 添加如下代码:! test1.f90 !! FUNCTIONS/SUBROUTINES exported from test1.dll:! test1 - subroutine !示例没有返回值的子例程 subroutine test1(a,b)! Expose subroutine test1 to users of this DLL !!DEC$ ATTRIBUTES C,DLLEXPORT::...
C语言调用Fortran.dll(Win10+VS2019|OneAPI,安装参考https://zhuanlan.zhihu.com/p/411167136) 1.创建Fortran的dll 1.1创建fortran的动态库,这里命名为f_dll.dll 1.2添加f_dll代码,右击“Resource file”---“添加”---“新建项” 1.3编写f_dll代码,编译。函数”tqf”功能为把输入的数dt和数组T所有元素乘10...