Using Fortran libraries from Python?
bhoel at web.de
Thu Jun 17 21:14:35 CEST 2004
Carl <phleum_nospam at chello.se> writes:
> 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
>>>> import LDSsobol
> 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
Googleing for "libf2c.so.0: undefined symbol: MAIN__" I found only 8
hits, some links broken, but also
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
int MAIN__( )
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.
bhoel at web.de / http://starship.python.net/crew/bhoel/
More information about the Python-list