From 1a46fc49d6b825b6711e0cca6b7c5e296564fefe Mon Sep 17 00:00:00 2001 From: p Date: Sun, 15 Nov 2026 21:55:26 +0100 Subject: [PATCH 1/3] embed: link libpython3., not the stable ABI stub py_libname cut LDLIBRARY at its first dot: libpython3.13.so gave -lpython3, the stable ABI stub, whose symbols the linker does not resolve through it (undefined Py_Initialize etc. with MKN_PYTHON_LIB_EMBED). Strip only the lib prefix and the library suffix. --- mod.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mod.cpp b/mod.cpp index 37da835..59b380a 100644 --- a/mod.cpp +++ b/mod.cpp @@ -131,8 +131,11 @@ class Python3Module : public mkn::mod::Module { std::string py_libname() const { return pyexec_for_string( - "import sysconfig; lib=sysconfig.get_config_var('LDLIBRARY');" - "print(lib[3:].split('.')[0] if lib.startswith('lib') else lib.split('.')[0])"); + // libpython3.13.so -> python3.13 (not python3: libpython3.so is the stable ABI stub, + // its symbols are not linkable through it), python313.dll -> python313 + "import re, sysconfig; lib=sysconfig.get_config_var('LDLIBRARY');" + "lib=lib[3:] if lib.startswith('lib') else lib;" + "print(re.sub(r'\\.(so|a|dylib|dll|lib)(\\..*)?$', '', lib))"); } std::string py_prefix() const { return pyexec_for_string("import sysconfig; print(sysconfig.get_config_var('prefix'))"); From dceabe3be1992455f8b5c510d482ce3d8e73d6f5 Mon Sep 17 00:00:00 2001 From: p Date: Sun, 15 Nov 2026 22:12:11 +0100 Subject: [PATCH 2/3] py_libname from sysconfig's LDVERSION (as python3-config --embed), python without it (Windows) --- mod.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mod.cpp b/mod.cpp index 59b380a..7ac903f 100644 --- a/mod.cpp +++ b/mod.cpp @@ -130,12 +130,12 @@ class Python3Module : public mkn::mod::Module { } std::string py_libname() const { + // as python3-config --embed: python (LDVERSION, e.g. 3.13, 3.13t), not + // the stable ABI stub libpython3 (it defines none of the API); Windows has no LDVERSION: + // python (python313.lib) return pyexec_for_string( - // libpython3.13.so -> python3.13 (not python3: libpython3.so is the stable ABI stub, - // its symbols are not linkable through it), python313.dll -> python313 - "import re, sysconfig; lib=sysconfig.get_config_var('LDLIBRARY');" - "lib=lib[3:] if lib.startswith('lib') else lib;" - "print(re.sub(r'\\.(so|a|dylib|dll|lib)(\\..*)?$', '', lib))"); + "import sys, sysconfig; v=sysconfig.get_config_var('LDVERSION');" + "print('python' + v if v else 'python{}{}'.format(*sys.version_info[:2]))"); } std::string py_prefix() const { return pyexec_for_string("import sysconfig; print(sysconfig.get_config_var('prefix'))"); From f122c205a124661ca64f23610047a91884da8ea5 Mon Sep 17 00:00:00 2001 From: p Date: Sun, 15 Nov 2026 22:13:01 +0100 Subject: [PATCH 3/3] py_libname: comment, sysconfig only --- mod.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod.cpp b/mod.cpp index 7ac903f..4bd54c2 100644 --- a/mod.cpp +++ b/mod.cpp @@ -130,9 +130,9 @@ class Python3Module : public mkn::mod::Module { } std::string py_libname() const { - // as python3-config --embed: python (LDVERSION, e.g. 3.13, 3.13t), not - // the stable ABI stub libpython3 (it defines none of the API); Windows has no LDVERSION: - // python (python313.lib) + // python (e.g. 3.13, 3.13t), from sysconfig (python3-config is not always + // installed): not the stable ABI stub libpython3, it defines none of the API. Windows has + // no LDVERSION: python (python313.lib) return pyexec_for_string( "import sys, sysconfig; v=sysconfig.get_config_var('LDVERSION');" "print('python' + v if v else 'python{}{}'.format(*sys.version_info[:2]))");