[Lldb-commits] [lldb] [LLDB] Fix Python lib path (PR #191565)
Alexandre Ganea via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 10 16:03:07 PDT 2026
https://github.com/aganea created https://github.com/llvm/llvm-project/pull/191565
When `LLDB_ENABLE_PYTHON_LIMITED_API` is ON (which defaults to ON with SWIG >= 4.2 and `LLDB_EMBED_PYTHON_HOME=OFF`), LLDB defines `Py_LIMITED_API`. This causes Python's `pyconfig.h` to emit:
```
#pragma comment(lib, "python3.lib")
```
This is the Windows MSVC auto-link directive for the Python Stable ABI import library. CMake's `FindPython3` correctly found and linked the version-specific `python313.lib` (with full path), but the `#pragma comment(lib)` adds an *additional* implicit link dependency on `python3.lib` using just the bare filename. The linker can't find it because the Python `libs` directory isn't in the default library search path.
This PR adds `target_link_directories` for `Python3_LIBRARY_DIRS` in `lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt`. This ensures the linker can find `python3.lib` (and any other Python libraries) in the Python installation's `libs` directory. The `PUBLIC` visibility propagates this to `liblldb.dll` which is where the actual link failure occurs.
>From 0ca1bb7e19228100b3788cfd9a2ebd084fe02f28 Mon Sep 17 00:00:00 2001
From: Alexandre Ganea <aganea at havenstudios.com>
Date: Fri, 10 Apr 2026 17:53:24 -0400
Subject: [PATCH] [LLDB] Fix Python lib path
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With LLDB_ENABLE_PYTHON_LIMITED_API, Python headers emit
```
```
CMake links python313.lib with a full path, but the pragma pulls in python3.lib
by name — linker error:
```
lld-link: error: could not open 'python3.lib': no such file or directory
```
---
lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
index 303e17a938912..0a839adfeba50 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/CMakeLists.txt
@@ -52,3 +52,8 @@ add_lldb_library(lldbPluginScriptInterpreterPython PLUGIN
target_include_directories(lldbPluginScriptInterpreterPython
PUBLIC ${Python3_INCLUDE_DIRS})
+
+if(Python3_LIBRARY_DIRS)
+ target_link_directories(lldbPluginScriptInterpreterPython
+ PUBLIC ${Python3_LIBRARY_DIRS})
+endif()
More information about the lldb-commits
mailing list