Building LLDB with python support on Windows x86 (64-bit)

Hello, I’m new to LLVM.
I’m currently trying to build LLVM from source but I keep running into link errors when I build lldb with the python dependency.
I’m able to build LLVM from source with clang and lldb successfully, but it fails when I enable the python dependency. I’ve gone through the lldb build docs
and all the LLVM cmake docs and searched the forums but I can’t figure out what I’m doing wrong.

I have the following installed:

  • Visual Studio 2022 preview 4 with: python development package, desktop development with C++ package, C++ clang compiler for windows 15.0.1, git for windows
  • Python 3.11.3 with debug binaries
  • GnuWin32 for CoreUtils and Make
  • SWIG for windows
  • Ninja 1.11.1
  • CMake 3.25.1

Commands:

cmake -G Ninja -S llvm -B build -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_MT=mt -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DLLVM_ENABLE_PROJECTS="clang;lldb" -DLLDB_ENABLE_PYTHON=ON -DPYTHON_HOME="C:/Program Files/Python311" -DLLDB_TEST_COMPILER="C:/Program Files (x86)/LLVM/bin/clang-cl.exe" -DLLVM_USE_LINKER=lld -DLLDB_INCLUDE_TESTS=OFF
cmake --build build --target install

Errors:

[4137/4642] Linking CXX shared library bin\liblldb.dll
FAILED: bin/liblldb.dll lib/liblldb.lib
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=tools\lldb\source\API\CMakeFiles\liblldb.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x86\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x86\mt.exe --manifests  -- C:\PROGRA~1\MICROS~2\2022\Preview\VC\Tools\Llvm\bin\lld-link.exe /nologo @CMakeFiles\liblldb.rsp  /out:bin\liblldb.dll /implib:lib\liblldb.lib /pdb:bin\liblldb.pdb /dll /version:16.0 /machine:X86 -fuse-ld=lld /INCREMENTAL:NO  && cd ."
LINK: command "C:\PROGRA~1\MICROS~2\2022\Preview\VC\Tools\Llvm\bin\lld-link.exe /nologo @CMakeFiles\liblldb.rsp /out:bin\liblldb.dll /implib:lib\liblldb.lib /pdb:bin\liblldb.pdb /dll /version:16.0 /machine:X86 -fuse-ld=lld /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:bin\liblldb.dll.manifest" failed (exit code 1) with the following output:
lld-link: warning: ignoring unknown argument '-fuse-ld=lld'
lld-link: error: undefined symbol: __declspec(dllimport) _Py_IsInitialized
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class lldb_private::python::PythonObject __cdecl lldb_private::python::ToSWIGHelper(void *, struct swig_type_info *))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class lldb_private::python::PythonObject __cdecl lldb_private::python::ToSWIGWrapper(class std::unique_ptr<class lldb::SBValue, struct std::default_delete<class lldb::SBValue>>))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class lldb_private::python::PythonObject __cdecl lldb_private::python::ToSWIGWrapper(class std::shared_ptr<class lldb_private::ValueObject>))
>>> referenced 258 more times

lld-link: error: undefined symbol: __declspec(dllimport) __PyObject_New
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SwigPyObject_New(void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl _wrap_new_SBAddress(struct _object *, struct _object *))
>>> referenced 101 more times

lld-link: error: undefined symbol: __declspec(dllimport) __Py_NoneStruct
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonWatchpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::Watchpoint> const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonFormatterCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::TypeImpl>))
>>> referenced 912 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyUnicode_FromString
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(_PyInit__lldb)
>>> referenced 6 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyObject_SetAttr
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_InitShadowInstance(struct _object *))

lld-link: error: undefined symbol: __declspec(dllimport) _PyTuple_New
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct SwigPyClientData * __cdecl SwigPyClientData_New(struct _object *))
>>> referenced by lldbPluginScriptInterpreterPython.lib(PythonDataObjects.cpp.obj):(public: __thiscall lldb_private::python::PythonTuple::PythonTuple(enum lldb_private::python::PyInitialValue))
>>> referenced 3 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyDict_New
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(_PyInit__lldb)
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct swig_type_info * __cdecl SWIG_pchar_descriptor(void))
>>> referenced 2 more times

lld-link: error: undefined symbol: __declspec(dllimport) __Py_Dealloc
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))
>>> referenced 881 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyType_Modified
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl SWIG_Python_NewPointerObj(struct _object *, void *, struct swig_type_info *, int))

lld-link: error: undefined symbol: __declspec(dllimport) __PyObject_CallFunction_SizeT
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class llvm::Expected<bool> __cdecl lldb_private::LLDBSwigPythonBreakpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::BreakpointLocation> const &, class lldb_private::StructuredDataImpl const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class llvm::Expected<bool> __cdecl lldb_private::LLDBSwigPythonBreakpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::BreakpointLocation> const &, class lldb_private::StructuredDataImpl const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(unsigned int __cdecl lldb_private::LLDBSwigPython_CalculateNumChildren(struct _object *, unsigned int))
>>> referenced 3 more times

lld-link: error: undefined symbol: __declspec(dllimport) __Py_FalseStruct
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class llvm::Expected<bool> __cdecl lldb_private::LLDBSwigPythonBreakpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::BreakpointLocation> const &, class lldb_private::StructuredDataImpl const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonWatchpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::Watchpoint> const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSWIGPythonCallThreadPlan(void *, char const *, class lldb_private::Event *, bool &))
>>> referenced 2 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyErr_Occurred
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class llvm::Expected<bool> __cdecl lldb_private::LLDBSwigPythonBreakpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::BreakpointLocation> const &, class lldb_private::StructuredDataImpl const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonWatchpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::Watchpoint> const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonFormatterCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::TypeImpl>))
>>> referenced 560 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyExc_SystemExit
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(class llvm::Expected<bool> __cdecl lldb_private::LLDBSwigPythonBreakpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::BreakpointLocation> const &, class lldb_private::StructuredDataImpl const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonWatchpointCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::StackFrame> const &, class std::shared_ptr<class lldb_private::Watchpoint> const &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonFormatterCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::TypeImpl>))
>>> referenced 20 more times

lld-link: error: undefined symbol: __declspec(dllimport) __Py_TrueStruct
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonFormatterCallbackFunction(char const *, char const *, class std::shared_ptr<class lldb_private::TypeImpl>))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSWIGPythonCallThreadPlan(void *, char const *, class lldb_private::Event *, bool &))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPython_UpdateSynthProviderInstance(struct _object *))
>>> referenced 2 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyFunction_Type
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(bool __cdecl lldb_private::LLDBSwigPythonCallTypeScript(char const *, void const *, class std::shared_ptr<class lldb_private::ValueObject> const &, void **, class std::shared_ptr<class lldb_private::TypeSummaryOptions> const &, class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> &))

lld-link: error: undefined symbol: __declspec(dllimport) _PyObject_CallFunctionObjArgs
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(int __cdecl SWIG_Python_ConvertPtrAndOwn(struct _object *, void **, struct swig_type_info *, int, int *))
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(void __cdecl SwigPyObject_dealloc(struct _object *))

lld-link: error: undefined symbol: __declspec(dllimport) _PyObject_CallMethodObjArgs
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct _object * __cdecl lldb_private::LLDBSwigPython_GetRecognizedArguments(struct _object *, class std::shared_ptr<class lldb_private::StackFrame> const &))

lld-link: error: undefined symbol: __declspec(dllimport) _PyModule_Create2
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(_PyInit__lldb)

lld-link: error: undefined symbol: __declspec(dllimport) _PyModule_GetDict
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(_PyInit__lldb)
>>> referenced by lldbPluginScriptInterpreterPython.lib(PythonDataObjects.cpp.obj):(public: class llvm::Expected<class lldb_private::python::PythonObject> __thiscall lldb_private::python::PythonModule::Get(class llvm::Twine const &))
>>> referenced by lldbPluginScriptInterpreterPython.lib(PythonDataObjects.cpp.obj):(public: class lldb_private::python::PythonDictionary __thiscall lldb_private::python::PythonModule::GetDictionary(void) const)
>>> referenced 2 more times

lld-link: error: undefined symbol: __declspec(dllimport) _PyCapsule_Import
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(_PyInit__lldb)
>>> referenced by tools\lldb\source\API\CMakeFiles\liblldb.dir\__\__\bindings\python\LLDBWrapPython.cpp.obj:(struct swig_type_info * __cdecl SWIG_pchar_descriptor(void))