From 56da8f9328dd2a2be1129d160b5896ac498522d4 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 27 Apr 2020 14:05:08 -0400 Subject: [PATCH 1/5] bpo-38728: Update PC/pyconfig.h to allow disabling pragma based auto-linking Define PY_NO_LINK_LIB to build extension disabling pragma based auto-linking. This is relevant when using build-system generator (e.g CMake) where the linking is explicitly handled --- PC/pyconfig.h.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index f4f57c5d270028..66a04d04539b6c 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -311,9 +311,13 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ #ifdef MS_COREDLL # if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) /* not building the core - must be an ext */ -# if defined(_MSC_VER) +# if defined(_MSC_VER) && !defined(PY_NO_LINK_LIB) /* So MSVC users need not specify the .lib file in their Makefile */ + /* Define PY_NO_LINK_LIB to build extension disabling pragma + based auto-linking. + This is relevant when using build-system generator (e.g CMake) where + the linking is explicitly handled */ # if defined(Py_GIL_DISABLED) # if defined(_DEBUG) # pragma comment(lib,"python314t_d.lib") @@ -331,7 +335,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ # pragma comment(lib,"python314.lib") # endif /* _DEBUG */ # endif /* Py_GIL_DISABLED */ -# endif /* _MSC_VER */ +# endif /* _MSC_VER && !PY_NO_LINK_LIB */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ From 7aa18a2a2e07ae194d7a8f4510557e8b87a684ee Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sun, 2 Apr 2023 14:20:48 +0400 Subject: [PATCH 2/5] Add a news entry --- .../next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst diff --git a/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst b/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst new file mode 100644 index 00000000000000..446b6d66c76dfb --- /dev/null +++ b/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst @@ -0,0 +1,2 @@ +``#pragma``-based linking with ``python3*.lib`` can now be switched off with +:c:expr:`PY_NO_LINK_LIB`. Patch by Jean-Christophe Fillion-Robin. From 29268cc8f2685c7ae928244f960f068e6c8409ff Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sun, 2 Apr 2023 16:42:32 +0400 Subject: [PATCH 3/5] Add documentation --- Doc/extending/windows.rst | 56 ++++++++++++++++++++++++++++++--------- Doc/whatsnew/3.14.rst | 4 +++ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Doc/extending/windows.rst b/Doc/extending/windows.rst index e366d6cb9f79e3..ea382df8a339b9 100644 --- a/Doc/extending/windows.rst +++ b/Doc/extending/windows.rst @@ -96,6 +96,13 @@ gives you access to spam's names, but does not create a separate copy. On Unix, linking with a library is more like ``from spam import *``; it does create a separate copy. +.. c:macro:: PY_NO_LINK_LIB + + Turn off the implicit, ``#pragma``-based linkage with the Python + library, performed inside CPython header files. + + .. versionadded:: 3.14 + .. _win-dlls: @@ -108,21 +115,46 @@ Using DLLs in Practice Windows Python is built in Microsoft Visual C++; using other compilers may or may not work. The rest of this section is MSVC++ specific. -When creating DLLs in Windows, you must pass :file:`pythonXY.lib` to the linker. -To build two DLLs, spam and ni (which uses C functions found in spam), you could -use these commands:: +When creating DLLs in Windows, you can use the CPython library in two ways:: + +1. By default, inclusion of :file:`PC/pyconfig.h` directly or via + :file:`Python.h` triggers an implicit, configure-aware link with the + library. The header file chooses :file:`pythonXY_d.lib` for Debug, + :file:`pythonXY.lib` for Release, and :file:`pythonX.lib` for Release with + the `Limited API `_ enabled. + + To build two DLLs, spam and ni (which uses C functions found in spam), you + could use these commands:: + + cl /LD /I/python/include spam.c + cl /LD /I/python/include ni.c spam.lib + + The first command created three files: :file:`spam.obj`, :file:`spam.dll` + and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python + functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find + the Python code thanks to the implicitly linked :file:`pythonXY.lib`. + + The second command created :file:`ni.dll` (and :file:`.obj` and + :file:`.lib`), which knows how to find the necessary functions from spam, + and also from the Python executable. + +2. Manually by defining :c:macro:`PY_NO_LINK_LIB` macro before including + :file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker. + + To build two DLLs, spam and ni (which uses C functions found in spam), you + could use these commands:: - cl /LD /I/python/include spam.c ../libs/pythonXY.lib - cl /LD /I/python/include ni.c spam.lib ../libs/pythonXY.lib + cl /LD /DPY_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib + cl /LD /DPY_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib -The first command created three files: :file:`spam.obj`, :file:`spam.dll` and -:file:`spam.lib`. :file:`Spam.dll` does not contain any Python functions (such -as :c:func:`PyArg_ParseTuple`), but it does know how to find the Python code -thanks to :file:`pythonXY.lib`. + The first command created three files: :file:`spam.obj`, :file:`spam.dll` + and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python + functions (such as :c:func:`PyArg_ParseTuple`), but it does know how to find + the Python code thanks to :file:`pythonXY.lib`. -The second command created :file:`ni.dll` (and :file:`.obj` and :file:`.lib`), -which knows how to find the necessary functions from spam, and also from the -Python executable. + The second command created :file:`ni.dll` (and :file:`.obj` and + :file:`.lib`), which knows how to find the necessary functions from spam, + and also from the Python executable. Not every identifier is exported to the lookup table. If you want any other modules (including Python) to be able to see your identifiers, you have to say diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index ce75b5fffc0a4c..373113200043fd 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1381,6 +1381,10 @@ Build changes * GNU Autoconf 2.72 is now required to generate :file:`configure`. (Contributed by Erlend Aasland in :gh:`115765`.) +* ``#pragma``-based linking with ``python3*.lib`` can now be switched off + with :c:expr:`Py_NO_LINK_LIB`. (Contributed by Jean-Christophe + Fillion-Robin in :gh:`82909`.) + .. _whatsnew314-pep761: PEP 761: Discontinuation of PGP signatures From 3658f4c58ec268428dd00d1bd834df4192766a51 Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sun, 2 Apr 2023 16:49:21 +0400 Subject: [PATCH 4/5] Rename PY_NO_LINK_LIB to Py_NO_LINK_LIB --- Doc/extending/windows.rst | 8 ++++---- .../Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst | 2 +- PC/pyconfig.h.in | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/extending/windows.rst b/Doc/extending/windows.rst index ea382df8a339b9..3b2bbf2ca01fe9 100644 --- a/Doc/extending/windows.rst +++ b/Doc/extending/windows.rst @@ -96,7 +96,7 @@ gives you access to spam's names, but does not create a separate copy. On Unix, linking with a library is more like ``from spam import *``; it does create a separate copy. -.. c:macro:: PY_NO_LINK_LIB +.. c:macro:: Py_NO_LINK_LIB Turn off the implicit, ``#pragma``-based linkage with the Python library, performed inside CPython header files. @@ -138,14 +138,14 @@ When creating DLLs in Windows, you can use the CPython library in two ways:: :file:`.lib`), which knows how to find the necessary functions from spam, and also from the Python executable. -2. Manually by defining :c:macro:`PY_NO_LINK_LIB` macro before including +2. Manually by defining :c:macro:`Py_NO_LINK_LIB` macro before including :file:`Python.h`. You must pass :file:`pythonXY.lib` to the linker. To build two DLLs, spam and ni (which uses C functions found in spam), you could use these commands:: - cl /LD /DPY_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib - cl /LD /DPY_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib + cl /LD /DPy_NO_LINK_LIB /I/python/include spam.c ../libs/pythonXY.lib + cl /LD /DPy_NO_LINK_LIB /I/python/include ni.c spam.lib ../libs/pythonXY.lib The first command created three files: :file:`spam.obj`, :file:`spam.dll` and :file:`spam.lib`. :file:`Spam.dll` does not contain any Python diff --git a/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst b/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst index 446b6d66c76dfb..0de47cf768c223 100644 --- a/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst +++ b/Misc/NEWS.d/next/Build/2023-04-02-14-20-29.gh-issue-82909.LGcZJy.rst @@ -1,2 +1,2 @@ ``#pragma``-based linking with ``python3*.lib`` can now be switched off with -:c:expr:`PY_NO_LINK_LIB`. Patch by Jean-Christophe Fillion-Robin. +:c:expr:`Py_NO_LINK_LIB`. Patch by Jean-Christophe Fillion-Robin. diff --git a/PC/pyconfig.h.in b/PC/pyconfig.h.in index 66a04d04539b6c..9e70303868e5de 100644 --- a/PC/pyconfig.h.in +++ b/PC/pyconfig.h.in @@ -311,10 +311,10 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ #ifdef MS_COREDLL # if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN) /* not building the core - must be an ext */ -# if defined(_MSC_VER) && !defined(PY_NO_LINK_LIB) +# if defined(_MSC_VER) && !defined(Py_NO_LINK_LIB) /* So MSVC users need not specify the .lib file in their Makefile */ - /* Define PY_NO_LINK_LIB to build extension disabling pragma + /* Define Py_NO_LINK_LIB to build extension disabling pragma based auto-linking. This is relevant when using build-system generator (e.g CMake) where the linking is explicitly handled */ @@ -335,7 +335,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ # pragma comment(lib,"python314.lib") # endif /* _DEBUG */ # endif /* Py_GIL_DISABLED */ -# endif /* _MSC_VER && !PY_NO_LINK_LIB */ +# endif /* _MSC_VER && !Py_NO_LINK_LIB */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ From 23c9af6ad4363a62055cb811b01b935b01e7af7a Mon Sep 17 00:00:00 2001 From: Oleg Iarygin Date: Sun, 2 Apr 2023 16:50:13 +0400 Subject: [PATCH 5/5] Fix `WARNING: Literal block expected; none found` --- Doc/extending/windows.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/extending/windows.rst b/Doc/extending/windows.rst index 3b2bbf2ca01fe9..56aa44e4e58c83 100644 --- a/Doc/extending/windows.rst +++ b/Doc/extending/windows.rst @@ -115,7 +115,7 @@ Using DLLs in Practice Windows Python is built in Microsoft Visual C++; using other compilers may or may not work. The rest of this section is MSVC++ specific. -When creating DLLs in Windows, you can use the CPython library in two ways:: +When creating DLLs in Windows, you can use the CPython library in two ways: 1. By default, inclusion of :file:`PC/pyconfig.h` directly or via :file:`Python.h` triggers an implicit, configure-aware link with the pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy