FAQ
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 "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

Search Discussions

  • Skip Montanaro at Jun 17, 2004 at 6:27 pm
    Carl> I have experimented with f2c and swig-generated wrappers to create
    Carl> python modules from Fortran files.

    ...

    Carl> Any help is appreciated!

    I'd take a look at f2py, part of the scipy package (and also available on
    its own):

    http://www.scipy.org/
    http://www.python.org/pypi?%3Aaction=search&name=f2py&_pypi_hidden=0

    Skip
  • Berthold Höllmann at Jun 17, 2004 at 7:14 pm

    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
    following:
    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
    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
  • Carl at Jun 18, 2004 at 4:16 pm

    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
  • Harry George at Jun 17, 2004 at 7:28 pm

    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
    following:
    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
    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.

    --
    harry.g.george at boeing.com
    6-6M21 BCA CompArch Design Engineering
    Phone: (425) 342-0007
  • Fernando Perez at Jun 18, 2004 at 12:18 am

    Carl wrote:

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 17, '04 at 1:44p
activeJun 18, '04 at 4:16p
posts6
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase