[英]how to add library compilation to numpy.distutils.core?
I'm trying make setup.py for my tiny module, which uses numpy. 我正在尝试为使用numpy的小模块创建setup.py。 To compile this module I need extra library which locates in same directory 要编译此模块,我需要位于同一目录中的额外库
ls -l audiotools
total 20
-rw-rw-r-- 1 rth rth 4405 Sep 9 10:58 audiotools.c
drwxr-xr-x 6 rth rth 4096 Sep 9 11:13 libresample-0.1.3
-rw-rw-r-- 1 rth rth 741 Sep 9 11:56 setup.py
So I need add something in setup.py which will call configure and make in libresample-0.1.3 and then add 'libresample.a' to the linker command. 因此,我需要在setup.py中添加一些东西,它将调用configure并在libresample-0.1.3中进行make,然后将'libresample.a'添加到链接器命令中。
I've tried used add_library, but it requires just source files but not whole source directory. 我试过使用add_library,但是它只需要源文件,而不需要整个源目录。 How I can do it? 我该怎么办?
This doesn't work. 这行不通。
def configuration(parent_package='', top_path=None):
import numpy
from numpy.distutils.misc_util import Configuration
config = Configuration('audiotools',parent_package,top_path)
config.add_extension('audiotools', ['audiotools.c'])
config.add_library('libresample',['libresample.a'])
return config
if __name__ == "__main__":
from numpy.distutils.core import setup
setup(
name = "audiotools",
version='0.01',
description='Python wrapper for GNU libresample-0.1.3 and reader of Wave 24bit files',
author='Ruben Tikidji-Hamburyan, Timur Pinin',
author_email='rth@nisms.krinc.ru, timpin@rambler.ru',
configuration=configuration
)
Thanks! 谢谢!
As far as i know this is quite a hassle. 据我所知,这很麻烦。 The usual approach is to basically require the lib to be installed on the system as a shared lib. 通常的方法是基本上要求该库作为共享库安装在系统上。
pyzmq do some kind of attempt on this, but it aint trivial: https://github.com/zeromq/pyzmq/blob/master/setup.py pyzmq对此进行了某种尝试,但它并不琐碎: https : //github.com/zeromq/pyzmq/blob/master/setup.py
The simplest way which I have found is to use os.system. 我发现的最简单的方法是使用os.system。 But it isn't look well for me. 但这对我来说不太好。
def configuration(parent_package='', top_path=None):
import numpy
from numpy.distutils.misc_util import Configuration
config = Configuration('audiotools',parent_package,top_path)
config.add_extension('audiotools', ['audiotools.c'],
extra_link_args=[os.getcwd()+'/libresample-0.1.3/libresample.a'],
depends=['libresample-0.1.3/libresample.a'],
return config
if __name__ == "__main__":
import os
os.system('pushd libresample-0.1.3 && ./configure CFLAGS=-fPIC && make &&popd')
from numpy.distutils.core import setup
setup(
name = "audiotools",
version='0.01',
description='Python wrapper for GNU libresample-0.1.3 and reader Wave 24 files',
author='Ruben Tikidji-Hamburyan, Timur Pinin',
author_email='rth@nisms.krinc.ru, timpin@rambler.ru',
configuration=configuration
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.