Debian Codegraph @

docs/c_api/c_build.rst

raw
1 .. currentmodule:: cairo
2
3 Build Integration
4 =================
5
6 To compile a Python extension using Pycairo you need to know where Pycairo and
7 cairo are located and what flags to pass to the compiler and linker.
8
9 1. Variant:
10
11 Similar to variant 2 but doesn't require pycairo to be loaded, which can be
12 problematic on Windows where by default cairo isn't in the dll search path
13 since Python 3.8.
14
15 .. code:: python
16
17 def get_include_path():
18 import os
19 from importlib.util import find_spec
20 spec = find_spec("cairo")
21 assert spec is not None
22 return os.path.join(os.path.dirname(spec.origin), 'include')
23
24 Compiler Flags:
25 * ``python -c "get_include_path()"``
26 * ``pkg-config --cflags cairo``
27
28 Linker Flags:
29 * ``pkg-config --libs cairo``
30
31 2. Variant:
32
33 Only available since version 1.16.0.
34
35 While Pycairo installs a pkg-config file, in case of virtualenvs,
36 installation to the user directory or when using wheels/eggs, pkg-config
37 will not be able to locate the .pc file. The :func:`get_include` function
38 should work in all cases, as long as Pycairo is in your Python search path.
39
40 Compiler Flags:
41 * ``python -c "import cairo; print(cairo.get_include())"``
42 * ``pkg-config --cflags cairo``
43
44 Linker Flags:
45 * ``pkg-config --libs cairo``
46
47 3. Variant:
48
49 This works with older versions, but with the limitations mentioned above.
50 Use it as a fallback if you want to support older versions or if your
51 module does not require virtualenv/pip support.
52
53 Compiler Flags:
54 * ``pkg-config --cflags py3cairo``
55
56 Linker Flags:
57 * ``pkg-config --libs py3cairo``