Re: [f2py] wrapping c with f2py

Ariel Balter <ariel-ZF+EKEZ8/[email protected]>
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Darn!! I wrote too soon!  I just got it to work with:


# -------------- padd.pyf -------------- #

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

# ----------------------------------------- #


I don't really understand how this all works yet, but I'm trying to 
follow various examples.  I'm a confirmed high-level programmer (or 
scripter as some like to call us).

I'm working up to be able to wrap some sophisticated c code, so I'll 
probably be back...

Thanks, Ariel

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
>

-- 
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Ariel I Balter, Ph.D.
Postdoc
Biological Monitoring/Modeling
Fundamental and Computational Sciences Directorate

Pacific Northwest National Laboratory Mail:
PO Box 999, MS P7-58,Richland, WA 99352
Shipping:
790 6th Street, MS P7-58, Richland, WA 99354

Tel:  509-376-7605 Cell:  509-713-0087
ariel.balter-Y2zl/[email protected]
www.arielbalter.com
www.pnl.gov
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.