Skip to content

Commit c2e81c4

Browse files
committed
Add documentation
1 parent dce9c38 commit c2e81c4

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

Doc/extending/windows.rst

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ gives you access to spam's names, but does not create a separate copy. On Unix,
9696
linking with a library is more like ``from spam import *``; it does create a
9797
separate copy.
9898

99+
.. c:macro:: PY_NO_LINK_LIB
100+
101+
Turn off the implicit, ``#pragma``-based linkage with the Python
102+
library, performed inside CPython header files.
103+
104+
.. versionadded:: 3.12
105+
99106

100107
.. _win-dlls:
101108

@@ -108,21 +115,46 @@ Using DLLs in Practice
108115
Windows Python is built in Microsoft Visual C++; using other compilers may or
109116
may not work. The rest of this section is MSVC++ specific.
110117

111-
When creating DLLs in Windows, you must pass :file:`pythonXY.lib` to the linker.
112-
To build two DLLs, spam and ni (which uses C functions found in spam), you could
113-
use these commands::
118+
When creating DLLs in Windows, you can use the CPython library in two ways::
119+
120+
1. By default, inclusion of :file:`PC/pyconfig.h` directly or via
121+
:file:`Python.h` triggers an implicit, configure-aware link with the
122+
library. The header file chooses :file:`pythonXY_d.lib` for Debug,
123+
:file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with
124+
the `Limited API <stable-application-binary-interface>`_ enabled.
125+
126+
To build two DLLs, spam and ni (which uses C functions found in spam), you
127+
could use these commands::
128+
129+
cl /LD /I/python/include spam.c
130+
cl /LD /I/python/include ni.c spam.lib
131+
132+
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
133+
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
134+
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
135+
the Python code thanks to the implicitly linked :file:`pythonXY.lib`.
136+
137+
The second command created :file:`ni.dll` (and :file:`.obj` and
138+
:file:`.lib`), which knows how to find the necessary functions from spam,
139+
and also from the Python executable.
140+
141+
2. Manually by defining :c:macro:`PY_NO_LINK_LIB` macro before including
142+
:file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker.
143+
144+
To build two DLLs, spam and ni (which uses C functions found in spam), you
145+
could use these commands::
114146

115-
cl /LD /I/python/include spam.c ../libs/pythonXY.lib
116-
cl /LD /I/python/include ni.c spam.lib ../libs/pythonXY.lib
147+
cl /LD /DPY_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib
148+
cl /LD /DPY_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib
117149

118-
The first command created three files: :file:`spam.obj`, :file:`spam.dll` and
119-
:file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such
120-
as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code
121-
thanks to :file:`pythonXY.lib`.
150+
The first command created three files: :file:`spam.obj`, :file:`spam.dll`
151+
and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python
152+
functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find
153+
the Python code thanks to :file:`pythonXY.lib`.
122154

123-
The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`),
124-
which knows how to find the necessary functions from spam, and also from the
125-
Python executable.
155+
The second command created :file:`ni.dll` (and :file:`.obj` and
156+
:file:`.lib`), which knows how to find the necessary functions from spam,
157+
and also from the Python executable.
126158

127159
Not every identifier is exported to the lookup table. If you want any other
128160
modules (including Python) to be able to see your identifiers, you have to say

Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,10 @@ Build Changes
869869
optimization levels (0, 1, 2) at once.
870870
(Contributed by Victor Stinner in :gh:`99289`.)
871871

872+
* ``#pragma``-based linking with ``python3*.lib`` can now be switched off
873+
with :c:expr:`PY_NO_LINK_LIB`. (Contributed by Jean-Christophe
874+
Fillion-Robin and Oleg Iarygin in :gh:`82909`.)
875+
872876

873877
C API Changes
874878
=============

0 commit comments

Comments
 (0)