代わりに文字列としてライブラリ名を渡す、コンパイルするソースとタプルを渡す:
setup.py
import sys
from distutils.core import setup
from distutils.command.build_clib import build_clib
from distutils.extension import Extension
from Cython.Distutils import build_ext
libhello = ('hello', {'sources': ['hello.c']})
ext_modules=[
Extension("demo", ["demo.pyx"])
]
def main():
setup(
name = 'demo',
libraries = [libhello],
cmdclass = {'build_clib': build_clib, 'build_ext': build_ext},
ext_modules = ext_modules
)
if __name__ == '__main__':
main()
のhello.c
int hello(void) { return 42; }
hello.h
int hello(void);
demo.pyx
cimport demo
cpdef test():
return hello()
は
cdef extern from "hello.h":
int hello()
コードを要旨として提供されていますdemo.pxd:https://gist.github.com/snorfalorpagus/2346f9a7074b432df959
「どのようにサードパーティ製のCを構築するために/ setup.pyのC++ライブラリ? "これは重要な質問です。(Cライブラリ用のPythonバインディングを作成する場合は、Python拡張をビルドする前にsetup.pyがソースからライブラリをビルドする必要があります)。私はこの文書をもっとうまくカバーしてほしいと思っています。 –
共有してくれてありがとう、私は決してこれを考え出さなかったでしょう。 https://github.com/hickford/primesieve-python/blob/master/setup.py –