[f2py] wrapping c with f2py

Pearu Peterson pearu.peterson at gmail.com
Tue Nov 24 10:55:31 EET 2009


Try the following signature file:

python module padd
  interface
    function cadd(a, b) result (c)
      integer, intent(c) :: cadd
      integer, intent(c) :: a
      integer, intent(c) :: b
      integer, intent(c) :: c
    end function cadd
  end interface
end python module padd

or a shorter one:

python module padd
  interface
    integer function cadd(a, b) result (c)
      intent(c)  ! all arguments will have intent(c)
      intent(c) cadd  ! function must be specified separately for intent(c)
      integer a, b, c
    end function cadd
  end interface
end python module padd

Also check the syntax rules of the signature files in

 http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#signature-file

Pearu

Ariel Balter wrote:
> Stunned by the almost instantaneous response!
> 
> Yes, installing python-dev did make that example work.  So, my system 
> appears to be able to handle the necessities now.  Thanks!
> 
> Now, perhaps you can please help me with this slightly more elaborate 
> example:
> 
> // ------------  cadd.c ------------------- //
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> 
> int cadd(int a, int b){
>    int c = a + b;
>    printf("sum of %i and %i is %i\n", a, b, c );
>    return c;
> }
> 
> // -------------------------------------------- //
> 
> # -------------- padd.pyf -------------- #
> 
> python module padd
>   interface
>     function cadd(a, b, c) result c
>       integer intent(c) cadd
>       integer intent(c) a
>       integer intent(c) b
>       integer intent(c) c
>     end function cadd
>   end interface
> end python module padd
> 
> # ----------------------------------------- #
> 
> 
> I can compile with "f2py -c pyadd.pyf cadd.c" just fine.  BUT, when I 
> try to import into python, I get:
> 
>>>>> import padd
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> ImportError: ./padd.so: undefined symbol: unknown_function_
> 
> I've tried a couple of different formats for the PYF file, but I don't 
> seem to have found the right approach.
> 
> Thanks much, Ariel
> 



More information about the f2py-users mailing list