OT? Distutils extension with shared libs
I know it is not directly related to numpy (even if it uses numpy.distutils), but I ask you folks how do you deal with code depending on other libs. In libIM7 projet ( https://launchpad.net/libim7 ), I wrap code from a device constructor with ctypes in order to read Particle Image Velocimetry (PIV) files stored by their software (format im7 and vc7). There is a dependency on zlib which is easy to solve in linux (installing zlib-dev package in debian). But as I want to use it also in windows (sharing the commercial dongle amongst various colleagues is a unconfortable solution), I am trying to configure the setup.py both for win and linux. But I am new to dev in windows... My questions are then: - how do you deal with dependencies in distutils? - what do you need to build against zlib (or another lib) in windows using distutils ? Thanks Fabricio
More precisely, the constructor provides C source code to access data and metadata with files ReadIM{7,x}.{c.h}. I wrote a tiny ctypes wrappers in order to have a object-oriented class in python that handling reading the data files written by the constructor software. One issue is that ReadIM7.h includes zlib.h. On linux, it is easy to install zlib-dev package. All is simple, as it is installed in standard repertory. On windows of course no standards. How would you then proceed? Do I have to distribute zlib.h, and also zconf.h, zlib.lib, libz.a and libz.dll.a needed to get it work ? Or a simpler solution is to only distribute binaries on this platform ? Other issue: with all these files in ./src, I have the following configuration: ext = Extension('_im7', sources=['src/ReadIM7.cpp', 'src/ReadIMX.cpp'], include_dirs=['src'],\ libraries=['zlib',],\ library_dirs=['src'],\ define_macros=[('_WIN32', None), ('BUILD_DLL', None)], \ extra_compile_args=['-ansi', '-pedantic', '-g', '-v']) it builds a _im7.pyd file that ctypes is not able to load as it expects a _im7.dll file with ctypes.cdll.loadlibrary('_im7')... Is their a way to make distutils build a .dll file that could be loaded by ctypes ? or using distutils in such a way is not the right way to go ? on linux, there is no trouble, distutils makes a _im7.so file that ctypes can easily load... Thanks ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Wed, Jul 7, 2010 at 12:34 AM, <silva@lma.cnrs-mrs.fr> wrote:
More precisely, the constructor provides C source code to access data and metadata with files ReadIM{7,x}.{c.h}. I wrote a tiny ctypes wrappers in order to have a object-oriented class in python that handling reading the data files written by the constructor software.
One issue is that ReadIM7.h includes zlib.h. On linux, it is easy to install zlib-dev package. All is simple, as it is installed in standard repertory. On windows of course no standards. How would you then proceed? Do I have to distribute zlib.h, and also zconf.h, zlib.lib, libz.a and libz.dll.a needed to get it work ?
Three solutions: - ask your users to build the software and install zlib by themselves. On windows, I am afraid it means you concretely limit your userbase to practically 0. - build zlib as part of the build process, and keep zlib internally. - include a copy of the zlib library (the binary) in the tarball.
Other issue: with all these files in ./src, I have the following configuration: ext = Extension('_im7', sources=['src/ReadIM7.cpp', 'src/ReadIMX.cpp'], include_dirs=['src'],\ libraries=['zlib',],\ library_dirs=['src'],\ define_macros=[('_WIN32', None), ('BUILD_DLL', None)], \ extra_compile_args=['-ansi', '-pedantic', '-g', '-v'])
it builds a _im7.pyd file that ctypes is not able to load as it expects a _im7.dll file with ctypes.cdll.loadlibrary('_im7')...
You cannot build a library loadable with ctypes with distutils nor numpy.distutils. You need to implement it in distutils, or copy the code from one of the project which implemented it cheers, David
Thanks for your answers.
Three solutions: - ask your users to build the software and install zlib by themselves. On windows, I am afraid it means you concretely limit your userbase to practically 0. - build zlib as part of the build process, and keep zlib internally. - include a copy of the zlib library (the binary) in the tarball.
You cannot build a library loadable with ctypes with distutils nor numpy.distutils. You need to implement it in distutils, or copy the code from one of the project which implemented it
Ok, the simplest may then to build _im7.dll with make or scons and include it as install_data in the python package... I was astonished that the process (building the shared object called by ctypes) that works on linux does not work in windows! By the way, do you have any example of project implementing it in distutils ?
participants (3)
-
David Cournapeau
-
Fabrice Silva
-
silva@lma.cnrs-mrs.fr