You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that you will need to run this command again every time you change your
180
+
extension.
181
+
Unlike Python, C has an explicit compilation step.
137
182
138
183
When your extension is compiled and installed, start Python and try to
139
184
import it.
@@ -522,6 +567,71 @@ Here is the entire source file, for your convenience:
522
567
:start-at: ///
523
568
524
569
570
+
.. _first-extension-other-tools:
571
+
572
+
Appendix: Other build tools
573
+
===========================
574
+
575
+
You should be able to follow this tutorial -- except the
576
+
*Running your build tool* section itself -- with a build tool other
577
+
than ``meson-python``.
578
+
579
+
The Python Packaging User Guide has a `list of recommended tools <https://packaging.python.org/en/latest/guides/tool-recommendations/#build-backends-for-extension-modules>`_;
580
+
be sure to choose one for the C language.
581
+
582
+
583
+
Workaround for missing PyInit function
584
+
--------------------------------------
585
+
586
+
If your build tool output complains about missing ``PyInit_spam``,
587
+
add the following function to your module for now:
588
+
589
+
.. code-block:: c
590
+
591
+
// A workaround
592
+
void *PyInit_spam(void) { return NULL; }
593
+
594
+
This is a shim for an old-style :ref:`initialization function <extension-export-hook>`,
595
+
which was required in extension modules for CPython 3.14 and below.
596
+
Current CPython will not call it, but some build tools may still assume that
597
+
all extension modules need to define it.
598
+
599
+
If you use this workaround, you will get the exception
600
+
``SystemError: initialization of spam failed without raising an exception``
601
+
instead of
602
+
``ImportError: dynamic module does not define module export function``.
603
+
604
+
605
+
Compiling directly
606
+
------------------
607
+
608
+
Using a third-party build tool is heavily recommended,
609
+
as it will take care of various details of your platform and Python
610
+
installation, of naming the resulting extension, and, later, of distributing
611
+
your work.
612
+
613
+
If you are building an extension for as *specific* system, or for yourself
614
+
only, you might instead want to run your compiler directly.
615
+
The way to do this is system-specific; be prepared for issues you will need
616
+
to solve yourself.
617
+
618
+
Linux
619
+
^^^^^
620
+
621
+
On Linux, the Python development package may include a ``python3-config``
622
+
command that prints out the required compiler flags.
623
+
If you use it, check that it corresponds to the CPython interpreter you'll use
0 commit comments