小编mom*_*mba的帖子

在Fortran代码中调用C函数/子例程

我正在尝试编译和链接调用c子例程的Fortran代码:

Fortran代码:

program adder
integer a,b
a=1
b=2
call addnums(a,b)
stop    
end program
Run Code Online (Sandbox Code Playgroud)

C代码:

void addnums( int* a, int* b ) 
{
    int c = (*a) + (*b);  /* convert pointers to values, then add them */
    printf("sum of %i and %i is %i\n", (*a), (*b), c );
}
Run Code Online (Sandbox Code Playgroud)

我在Windows环境中使用以下命令进行编译和链接.

ifort -c adder.f
cl -c addnums.c
ifort -o add adder.obj addnums.obj
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.
-out:add.exe 
-subsystem:console 
adder.obj 
addnums.obj 
adder.obj …
Run Code Online (Sandbox Code Playgroud)

c fortran compilation fortran-iso-c-binding

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

compilation ×1

fortran ×1

fortran-iso-c-binding ×1