wrapping C in python.

This is the place for queries that don't fit in any of the other categories.

wrapping C in python.

Postby dauphin » Thu May 08, 2014 6:39 am

Hi

I have a C program with several functions for make spheric harmonics calculs. And i would like to include them into my python program.

I try to made a python lib whith Cython after compile my C code and recorver my .so file.
But that doesn't work and seems to be a complicated solution.

what is the best tools to do that ?
thanks
Last edited by Mekire on Thu May 08, 2014 7:10 am, edited 1 time in total.
Reason: First post lock.
dauphin
 
Posts: 2
Joined: Thu May 08, 2014 6:24 am

Re: wrapping C in python.

Postby Mekire » Thu May 08, 2014 7:53 am

I'm not particularly experienced in it, but you could read this post (not the whole thread; just that post) and see if it helps:
http://python-forum.org/viewtopic.php?f=6&t=10875#p14163

-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: wrapping C in python.

Postby stranac » Thu May 08, 2014 12:09 pm

CFFI is the way to go.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1155
Joined: Thu Feb 07, 2013 3:42 pm

Re: wrapping C in python.

Postby micseydel » Thu May 08, 2014 7:12 pm

I'm not familiar with CFFI, but when I used ctypes in the past, it was extremely simple and portable.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: wrapping C in python.

Postby Tcll » Thu May 08, 2014 11:07 pm

here's another method...
probably not the best though...
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: wrapping C in python.

Postby dauphin » Tue May 13, 2014 2:45 am

thanks you for all your answers.

it's works with ctypes, i can easily call C functions.

But, i have a problem with nested library.

I have file primitive.c which calculate basic primitive functions.
And a file legendre.c which need to call primitive functions to calculate legendre.

i generate library.so of both.
But I can not calculate legendre because primitive functions are never recognized.

i don't want to make juste one Big file, but link the two files in python
how can I do it?
Thanks :D
dauphin
 
Posts: 2
Joined: Thu May 08, 2014 6:24 am

Re: wrapping C in python.

Postby micseydel » Tue May 13, 2014 3:11 am

You'll have to be more detailed about the exact commands/files/code. From what you said, it sounds like you might be overwriting one of the files when you compile the second, but there's no certainty without all the details.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1390
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 6 guests