tags:

views:

39

answers:

4

I used f2c to translate a huge Fortran subroutine into C. The header says the following:

/* 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
*/

I am using ubuntu 10.04. How can I link the object file with libf2c?

+2  A: 

You would have to install the libf2c2-dev package -- but as the f2c package already depends on it, all you may need is to add -lf2c to your Makefile.

Dirk Eddelbuettel
+1  A: 

By passing -lf2c -lm to the line which will create the executable from the objects. Which compiler are you using on Ubuntu? GCC?

gcc -c fourier.c -lf2c -lm

Could be as simple as that.

sixlettervariables
A: 

Well - no direct answer to your linking problems, but:

Since you're working with Linux: Why don't you compile you fortran code as is and link it directly with the C-code? GCC can do that. Converting the code is of course doable but it is by no way required.

Nils

Nils Pipenbrinck
Because I need to use the resulting C code in a Java library. :P
Earl Bellinger
With the ISO_C_Binding, you can declare Fortran subroutines to use the C calling convention, so that they are directly callable just as if they were C.
M. S. B.
@Earl Bellinger - Oh.. I see. Java, C, JNI-Stuff.. (I currently work in that field as well). I know of no direct way to do this. It could be doable with GCC, but I haven't ever tried it. Would be a great blogpost if you get it working.. Otherwise: Just write a wrapper in C :-)
Nils Pipenbrinck
+1  A: 

Are you compiling the resulting C file with gcc? Then add "-lf2c -lm" to the gcc compile command.

Why not compile with a Fortran compiler, such as gfortran? It's easily available for Ubuntu.

M. S. B.