On Sun, Dec 23, 2012 at 11:48 AM, Aronne Merrelli
<aronne.merre...@gmail.com> wrote:
> Hi,
>
> I'm trying to run f2py and running into some trouble. Starting from
> http://www.scipy.org/Cookbook/F2Py, and the very simple 'Wrapping Hermite
> Polynomial' example, I can get the pyf file created with no issues. The
> system I am using is RedHat linux, and has several Fortran compilers:
>
> $ f2py -c --help-fcompiler
> <snip>
> Fortran compilers found:
>   --fcompiler=g95      G95 Fortran Compiler (0.92)
>   --fcompiler=gnu      GNU Fortran 77 compiler (3.4.6)
>   --fcompiler=gnu95    GNU Fortran 95 compiler (4.1.2)
>   --fcompiler=intelem  Intel Fortran Compiler for 64-bit apps (11.1)
>
> All of these will successfully create the .so file except for g95, but when
> I try to import into python I get this ImportError for any of the other
> three compilers:
>
> In [5]: import hermite
> ImportError: ./hermite.so: undefined symbol: c06ebf_
>
> If I look at the shared object I find that symbol here:
>
> $ nm hermite.so
> <snip>
> 00000000000043c0 T array_from_pyobj
>                  U c06eaf_
>                  U c06ebf_

This "U" here means "undefined" (see "man nm"). I don't know if this
symbol is something that f2py introduces, or if it is present in the
original Fortran sources. One way to know for sure is to examine all
.f90 and .c files generated by f2py and search for this symbol and
make sure that these subroutines/functions are linked in.

> And that about hits my limit of compiler knowledge, as I am pretty much a
> novice with these things. Any ideas on what is going wrong here, or
> suggestions of things to try?

I personally wrap Fortran like any other C code using the
iso_c_binding Fortran module. I use Cython, but you can also use
ctypes or any other method. See here:

http://fortran90.org/src/best-practices.html#interfacing-with-c
http://fortran90.org/src/best-practices.html#interfacing-with-python

That way it is easy to see what is going on under the hood.

Ondrej
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to