Using Fortran libraries from Python?

C

Carl

I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

I think I'm missing something when I'm building the Python module, because
when I import the built module the Python interpreter returns the
following:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "LDSsobol.py", line 4, in ?
import _LDSsobol
ImportError: /usr/lib/libf2c.so.0: undefined symbol: MAIN__

This is how I built LDSsobol:
gcc -c LDSsobol.c
gcc -c LDSsobol_wrap.c -I/usr/include/python
gcc -shared LDSsobol.o LDSsobol_wrap.o -l f2c -o _LDSsobol.so

Any help is appreciated!

Carl
 
B

Berthold Höllmann

Carl said:
I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

I think I'm missing something when I'm building the Python module, because
when I import the built module the Python interpreter returns the
following:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "LDSsobol.py", line 4, in ?
import _LDSsobol
ImportError: /usr/lib/libf2c.so.0: undefined symbol: MAIN__

This is how I built LDSsobol:

Hello Carl,

Googleing for "libf2c.so.0: undefined symbol: MAIN__" I found only 8
hits, some links broken, but also

<http://www.physics.orst.edu/~bertrand/slatec/jnislatec/JNI_Slatec.html>

where I found:

Currently users of f2c will probably encounter the following message:
"libf2c.so.0: undefined symbol: MAIN__ ". Again, the culprit is that
all references must be resolved, and libf2c.so unfortunately contains
a reference to some dummy function. Fortunately the fix is simple,
include the following snippet in your C native source (in our example
mynativecalls.c):

int MAIN__( )
{ return(0);
}

Another solution (not tested) could be to use "-lg2c" instead of
"-lf2c". As I understand it, the g77 runtime library is derived from
the f2c runtime library. An even better (in my opinion) solution would
be to use "f2py" from <http://cens.ioc.ee/projects/f2py2e/>, a tool to
wrap python (and C) code for python.

Regards
Berthold
 
H

Harry George

Carl said:
I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

I think I'm missing something when I'm building the Python module, because
when I import the built module the Python interpreter returns the
following:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "LDSsobol.py", line 4, in ?
import _LDSsobol
ImportError: /usr/lib/libf2c.so.0: undefined symbol: MAIN__

This is how I built LDSsobol:


Any help is appreciated!

Carl

Did you start with pyfort?
http://sourceforge.net/projects/pyfortran

I haven't used it personally, but it seems to be addressing your
concerns, without ad hoc SWIGing.
 
F

Fernando Perez

Carl said:
I have experimented with f2c and swig-generated wrappers to create python
modules from Fortran files.

Don't bother, just use f2py. It works beautifully (we use it everyday in
production codes).

Best,

f
 
C

Carl

Another solution (not tested) could be to use "-lg2c" instead of
"-lf2c". As I understand it, the g77 runtime library is derived from
the f2c runtime library.

This seems to work! How did you know?
An even better (in my opinion) solution would
be to use "f2py" from <http://cens.ioc.ee/projects/f2py2e/>, a tool to
wrap python (and C) code for python.

I will try both "f2py" and all other possible solution suggestions to my
problem.

I'm positively overwhelmed by your response. You've saved me a great deal of
trouble and (I don't know how many) hours of tedious trial and error work.

Thank you!

Carl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top