Re: Using a static library in a C extension for Python

2014-01-23 Thread 88888 Dihedral
On Thursday, January 23, 2014 3:22:52 AM UTC+8, lgabiot wrote:
 Le 22/01/14 18:31, 8 Dihedral a écrit :
 
 
 
 
 
  Check the  C source code generated
 
  by Pyrex and check cython for what u
 
  want, but I did try that out in any
 
  mobile phone or flat panel
 
  programming.
 
 
 
 
 
 Thanks a lot for your answer.
 
 
 
 I didn't use Pyrex or other tool, but wrote myself the C python 
 
 wrapping, using the Python C/API documentation 
 
 (http://docs.python.org/2/c-api/). I then used the distutils tool (via a 
 
 setup.py file) to build my extension.
 
 While there is several function in my C code, only one needed to be 
 
 accessed by python.
 
 
 
 I'll check Cython then, but is there any tweaking of the setup.py file 
 
 using distutils that will help me compile the extension with the cairo 
 
 lib embedded into it?

There are some design concerns in 
writing  python scripts that might
be modified for fast execution speeds in some platforms.

Well, reducing basic operation 
overheads in well factored critical 
parts does help in getting the 
desired results faster.

 
-- 
https://mail.python.org/mailman/listinfo/python-list


Using a static library in a C extension for Python

2014-01-22 Thread lgabiot

Hello,

working on OS X 10.8.5
Python 2.7

I've written a simple C extension for Python that uses the cairo graphic 
library.

It works well, and I can call it from Python with no problem.
The only drawback is that I need to have the cairo library installed on 
my system (so it seems my extension calls dynamically the cairo library).
I believe this because it doesn't work on a system where cairo is not 
installed.


Is it possible to link statically cairo to my extension, so that even if 
cairo is not installed on a computer, the code will run?


I guess I would need to modify the setup.py file using distutils to 
compile cairo statically into my .so file?


Or am I completely wrong?

If someone has a hint...

thanks!

--
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread 88888 Dihedral
On Wednesday, January 22, 2014 7:01:50 PM UTC+8, lgabiot wrote:
 Hello,
 
 
 
 working on OS X 10.8.5
 
 Python 2.7
 
 
 
 I've written a simple C extension for Python that uses the cairo graphic 
 
 library.
 
 It works well, and I can call it from Python with no problem.
 
 The only drawback is that I need to have the cairo library installed on 
 
 my system (so it seems my extension calls dynamically the cairo library).
 
 I believe this because it doesn't work on a system where cairo is not 
 
 installed.
 
 
 
 Is it possible to link statically cairo to my extension, so that even if 
 
 cairo is not installed on a computer, the code will run?
 
 
 
 I guess I would need to modify the setup.py file using distutils to 
 
 compile cairo statically into my .so file?
 
 
 
 Or am I completely wrong?
 
 
 
 If someone has a hint...
 
 
 
 thanks!

Check the  C source code generated 
by Pyrex and check cython for what u 
want, but I did try that out in any 
mobile phone or flat panel
programming.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread lgabiot

Le 22/01/14 18:31, 8 Dihedral a écrit :



Check the  C source code generated
by Pyrex and check cython for what u
want, but I did try that out in any
mobile phone or flat panel
programming.



Thanks a lot for your answer.

I didn't use Pyrex or other tool, but wrote myself the C python 
wrapping, using the Python C/API documentation 
(http://docs.python.org/2/c-api/). I then used the distutils tool (via a 
setup.py file) to build my extension.
While there is several function in my C code, only one needed to be 
accessed by python.


I'll check Cython then, but is there any tweaking of the setup.py file 
using distutils that will help me compile the extension with the cairo 
lib embedded into it?



--
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread Gregory Ewing

lgabiot wrote:

Le 22/01/14 18:31, 8 Dihedral a écrit :


Check the  C source code generated
by Pyrex ...



Thanks a lot for your answer.


We suspect that 8 Dihedral is actually a bot,
so you're *probably* wasting your time attempting
to engage it in conversation.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread Christian Gollwitzer

Hi,

Am 22.01.14 12:01, schrieb lgabiot:

Is it possible to link statically cairo to my extension, so that even if
cairo is not installed on a computer, the code will run?

I guess I would need to modify the setup.py file using distutils to
compile cairo statically into my .so file?


I've done it for a similar problem (linking HDF statically including its 
dependencies zlib and libjpeg), but I did write the Makefile by hand 
instead of using distutils.


First, you need to compile a static version of cairo. I.e., you probably 
have got some libcairo.2.dylib or similar. This can't be used, you must 
end up with a libcairo.a archive, by passing --disable-shared 
--enable-static to the configure script. For this to work, the code 
must be position-independent (--with-pic in autoconf). This is a no-op 
on OSX, where all code is position-independent, but is important if you 
plan to port it to Linux. Then, during the linking step of your 
extension, you need to link against that statically compiled version of 
libcairo. In a Makefile, you would pass -L/path/to/thelibrary -lcairo 
to the compiler invocation for the linking step. I don't know distutils 
enough, but maybe you can either pass LDFLAGS to it to do this or 
directly point to that version of cairo.



Or am I completely wrong?


I'm a big fan of static linkage in that case, too.
There might be another issue with the license of the library. Cairo is 
both LGPL and MPL. For LGPL, only dynamic linking is without doubt, for 
MPL it seems to be accepted to link statically. It all depends on 
whether you plan to pass on the binary to another person.
To circumvent this problem, it might be feasable to just install 
libcairo along with you extension.


Then, the exact same version of python must be used on both computers. 
Since the extension loading mechanism completely relies on the OS 
dynamic linker, it is not possible to load an extension into a different 
version of python than it was built for. Sadly, nobody implemented a 
system like Tcl's stubs, where an array of function pointers gets passed 
to the extension. This system allows to load an extension into later 
versions of the host program.


Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread lgabiot

Le 22/01/14 23:09, Gregory Ewing a écrit :


We suspect that 8 Dihedral is actually a bot,
so you're *probably* wasting your time attempting
to engage it in conversation.



Thanks,
so that will be my first real experience of the Turing test!!!



--
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread lgabiot

thanks a lot for your very precise answer!

shortly, as I'm running out of time right now:
I've got here a lot of informations, so I'll dig in the directions you 
gave me. It will be a good compiling exercise... (I'm really new at all 
this).



--
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread Chris Angelico
On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer aurio...@gmx.de wrote:
 There might be another issue with the license of the library. Cairo is both
 LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it
 seems to be accepted to link statically. It all depends on whether you plan
 to pass on the binary to another person.
 To circumvent this problem, it might be feasable to just install libcairo
 along with you extension.

 Then, the exact same version of python must be used on both computers. Since
 the extension loading mechanism completely relies on the OS dynamic linker,
 it is not possible to load an extension into a different version of python
 than it was built for.

If you can tie in with your OS's package manager, that would solve all
of these problems. You get the OS-supplied Pythom and the OS-supplied
libcairo; grabbing libcairo-dev (or, on my Debian system,
libcairo2-dev to go with libcairo2) gets you what you need to build
your extension; you then might even package your extension the same
way, and then simply declare dependencies. Can save a HUGE amount of
trouble.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using a static library in a C extension for Python

2014-01-22 Thread lgabiot

Le 23/01/14 03:33, Chris Angelico a écrit :

On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer aurio...@gmx.de wrote:

There might be another issue with the license of the library. Cairo is both
LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it
seems to be accepted to link statically. It all depends on whether you plan
to pass on the binary to another person.
To circumvent this problem, it might be feasable to just install libcairo
along with you extension.

Then, the exact same version of python must be used on both computers. Since
the extension loading mechanism completely relies on the OS dynamic linker,
it is not possible to load an extension into a different version of python
than it was built for.


If you can tie in with your OS's package manager, that would solve all
of these problems. You get the OS-supplied Pythom and the OS-supplied
libcairo; grabbing libcairo-dev (or, on my Debian system,
libcairo2-dev to go with libcairo2) gets you what you need to build
your extension; you then might even package your extension the same
way, and then simply declare dependencies. Can save a HUGE amount of
trouble.

ChrisA



thank you very much for your answer, I'll work on your informations.
--
https://mail.python.org/mailman/listinfo/python-list