Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用f2c后的链接_C_Linker_Fortran - Fatal编程技术网

使用f2c后的链接

使用f2c后的链接,c,linker,fortran,C,Linker,Fortran,我使用f2c将一个巨大的Fortran子程序转换为C。标题如下所示: /* fourier.f -- translated by f2c (version 20090411). You must link the resulting object file with libf2c: on Microsoft Windows system, link with libf2c.lib; on Linux or Unix systems, link with .../path/t

我使用f2c将一个巨大的Fortran子程序转换为C。标题如下所示:

/* fourier.f -- translated by f2c (version 20090411).
   You must link the resulting object file with libf2c:
    on Microsoft Windows system, link with libf2c.lib;
    on Linux or Unix systems, link with .../path/to/libf2c.a -lm
    or, if you install libf2c.a in a standard place, with -lf2c -lm
    -- in that order, at the end of the command line, as in
        cc *.o -lf2c -lm
    Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,

        http://www.netlib.org/f2c/libf2c.zip
*/

我正在使用ubuntu 10.04。如何将对象文件与libf2c链接?

您必须安装
libf2c2 dev
软件包——但由于
f2c
软件包已经依赖于它,您可能需要的只是将
-lf2c
添加到Makefile中

-lf2c-lm
传递到将从对象创建可执行文件的行。你在Ubuntu上使用哪种编译器?GCC

gcc -c fourier.c -lf2c -lm

可能就这么简单。

好吧-没有直接的链接问题的答案,但是:

既然您使用的是Linux:为什么不按原样编译fortran代码,并将其与C代码直接链接?GCC可以做到这一点。转换代码当然是可行的,但决不是必需的


Nils

您是否使用gcc编译生成的C文件?然后将“-lf2c-lm”添加到gcc编译命令中


为什么不使用Fortran编译器(如gfortran)进行编译?Ubuntu很容易使用它。

因为我需要在Java库中使用生成的C代码:p通过ISO_C_绑定,您可以声明Fortran子例程以使用C调用约定,这样它们就可以直接调用,就像它们是C一样。@Earl Bellinger-Oh。。我懂了。Java、C、JNI之类的东西。。(我目前也在该领域工作)。我知道没有直接的方法可以做到这一点。使用GCC是可行的,但我从未尝试过。如果你能让它工作起来,那将是一篇很棒的博客文章。。否则:只需用C:-)编写一个包装器元问题:似乎您正试图从Java访问用Fortran编写的FFT函数。。为什么不走捷径,忽略旧的Fortran内容,并将Java代码链接到FFTW库。无论如何,它的性能很可能比Fortran代码更高。你能帮我一下吗?我刚学了Fortran,对它知之甚少。我有一个用Java编写的程序,需要得到傅里叶正弦平方和级数的系数。我的教授写了一个Fortran程序来做这种事情。