Using Fortran libraries from Python?

Berthold Höllmann bhoel at
Thu Jun 17 21:14:35 CEST 2004

Carl <phleum_nospam at> 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
> following:
>>>> import LDSsobol
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "", line 4, in ?
>     import _LDSsobol
> ImportError: /usr/lib/ 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

Hello Carl,

Googleing for " 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:
" undefined symbol: MAIN__ ". Again, the culprit is that
all references must be resolved, and 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__( )
 {  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 <>, a tool to
wrap python (and C) code for python.

bhoel at /

More information about the Python-list mailing list