Can I create a Cython static library using distutils?

I would like to create a Cython static library using distutils. I do not want this to be a real Python extension that can be imported. I just want to compile the code and put the objects in a static library. The code for creating a dynamic library is very simple,

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
   cmdclass = {'build_ext':build_ext},
   ext_modules = [Extension("test",["test.pyx"])]
)

Is there an easy way to make it static?

+4
source share
2 answers

Distutils is very limited and not configured for static builds. I would advise you to use something else to compile the static library part of your project.

Cython C, public api cdef Cython. Cython C, .h .c .

+1

Fyi, numpy distutils, , , , , ,

from Cython.Compiler.Main import compile
from numpy.distutils.misc_util import Configuration

compile('test.pyx')
config = Configuration(...)
config.add_installed_library('test',
                         ['test.c'],
                         'test',
                         {'include_dirs':[get_python_inc()]})
0

Source: https://habr.com/ru/post/1534946/


All Articles