1PYTHON setup.py build_ext --inplace
2PYTHON -c "import a"
3PYTHON -c "import b"
4
5######## setup.py ########
6
7from Cython.Build import cythonize
8from distutils.core import setup
9
10setup(
11    ext_modules = cythonize("*.pyx"),
12)
13
14######## a.pxd ########
15# cython: preliminary_late_includes_cy28=True
16
17cdef extern from "a_early.h":
18  ctypedef int my_int
19
20cdef extern from "a_late.h":
21    my_int square_value_plus_one()
22
23cdef my_int my_value "my_value"
24
25cdef my_int square "square"(my_int x)
26
27######## a.pyx ########
28
29my_value = 10
30
31cdef my_int square "square"(my_int x):
32    return x * x
33
34assert square_value_plus_one() == 101
35
36# Square must be explicitly used for its proto to be generated.
37cdef my_int use_square(x):
38  return square(x)
39
40######## a_early.h ########
41
42typedef int my_int;
43
44######## a_late.h ########
45
46static my_int square_value_plus_one() {
47  return square(my_value) + 1;
48}
49
50######## b.pyx ########
51
52cimport a
53
54# Likewise, a.square must be explicitly used.
55assert a.square(a.my_value) + 1 == 101
56assert a.square_value_plus_one() == 101
57